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 Dec 16, 2024
1 parent effe7ec commit b77a009
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 64 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 @@ -21,6 +21,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 @@ -148,10 +151,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_()
}
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,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 b77a009

Please sign in to comment.