Skip to content

Commit

Permalink
Opentelemetry instrumentation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusz-reichert authored and m-reichert committed Nov 14, 2024
1 parent 9bc68fa commit 95f522f
Show file tree
Hide file tree
Showing 20 changed files with 368 additions and 71 deletions.
33 changes: 1 addition & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ default-run = "electrs"
liquid = ["elements"]
electrum-discovery = ["electrum-client"]
bench = []
default = ["no-otlp-tracing"]
otlp-tracing = [
"tracing/max_level_trace",
"tracing-subscriber",
"opentelemetry",
"tracing-opentelemetry",
"opentelemetry-otlp",
"opentelemetry-semantic-conventions"
]
no-otlp-tracing = [
"tracing/max_level_off"
]

[dependencies]
arraydeque = "0.5.1"
Expand Down Expand Up @@ -54,12 +66,12 @@ hyper = "0.14"
hyperlocal = "0.8"
# close to same tokio version as dependent by hyper v0.14 and hyperlocal 0.8 -- things can go awry if they mismatch
tokio = { version = "1", features = ["sync", "macros", "rt-multi-thread", "rt"] }
opentelemetry = { version = "0.20.0", features = ["rt-tokio"] }
tracing-opentelemetry = "0.21.0"
opentelemetry-otlp = { version = "0.13.0", default-features = false, features = ["http-proto", "reqwest-client"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
opentelemetry-semantic-conventions = "0.12.0"
tracing = { version = "0.1.40", features = ["async-await", "log"] }
opentelemetry = { version = "0.20.0", features = ["rt-tokio"], optional = true }
tracing-opentelemetry = { version = "0.21.0", optional = true }
opentelemetry-otlp = { version = "0.13.0", default-features = false, features = ["http-proto", "reqwest-client"], optional = true }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"], optional = true }
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }

# optional dependencies for electrum-discovery
electrum-client = { version = "0.8", optional = true }
Expand Down
17 changes: 16 additions & 1 deletion src/bin/electrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use electrs::{
signal::Waiter,
};

#[cfg(feature = "otlp-tracing")]
use electrs::otlp_trace;

#[cfg(feature = "liquid")]
use electrs::elements::AssetRegistry;
use electrs::metrics::MetricOpts;
Expand Down Expand Up @@ -142,10 +145,22 @@ fn run_server(config: Arc<Config>) -> Result<()> {
Ok(())
}

fn main() {
fn main_() {
let config = Arc::new(Config::from_args());
if let Err(e) = run_server(config) {
error!("server failed: {}", e.display_chain());
process::exit(1);
}
}

#[cfg(feature = "no-otlp-tracing")]
fn main() {
main_();
}

#[cfg(feature = "otlp-tracing")]
#[tokio::main]
async fn main() {
let _tracing_guard = otlp_trace::init_tracing("electrs");
main_()
}
16 changes: 9 additions & 7 deletions src/bin/tx-fingerprint-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ fn main() {

//info!("{:?},{:?}", txid, blockid);

let prevouts = chain.lookup_txos(
tx.input
.iter()
.filter(|txin| has_prevout(txin))
.map(|txin| txin.previous_output)
.collect(),
).unwrap();
let prevouts = chain
.lookup_txos(
tx.input
.iter()
.filter(|txin| has_prevout(txin))
.map(|txin| txin.previous_output)
.collect(),
)
.unwrap();

let total_out: u64 = tx.output.iter().map(|out| out.value.to_sat()).sum();
let small_out = tx
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ impl Config {
stderrlog::Timestamp::Off
});
log.init().expect("logging initialization failed");

let config = Config {
log,
network_type,
Expand Down
Loading

0 comments on commit 95f522f

Please sign in to comment.