Skip to content

Commit 0c1a6eb

Browse files
mario-reim-reichert
authored andcommitted
Opentelemetry instrumentation implementation
1 parent 3ad081e commit 0c1a6eb

File tree

18 files changed

+284
-64
lines changed

18 files changed

+284
-64
lines changed

Cargo.lock

Lines changed: 1 addition & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ default-run = "electrs"
1616
liquid = ["elements"]
1717
electrum-discovery = ["electrum-client"]
1818
bench = []
19+
default = ["no-otlp-tracing"]
20+
otlp-tracing = [
21+
"tracing/max_level_trace",
22+
"tracing-subscriber",
23+
"opentelemetry",
24+
"tracing-opentelemetry",
25+
"opentelemetry-otlp",
26+
"opentelemetry-semantic-conventions"
27+
]
28+
no-otlp-tracing = [
29+
"tracing/max_level_off"
30+
]
1931

2032
[dependencies]
2133
arraydeque = "0.5.1"
@@ -54,12 +66,12 @@ hyper = "0.14"
5466
hyperlocal = "0.8"
5567
# close to same tokio version as dependent by hyper v0.14 and hyperlocal 0.8 -- things can go awry if they mismatch
5668
tokio = { version = "1", features = ["sync", "macros", "rt-multi-thread", "rt"] }
57-
opentelemetry = { version = "0.20.0", features = ["rt-tokio"] }
58-
tracing-opentelemetry = "0.21.0"
59-
opentelemetry-otlp = { version = "0.13.0", default-features = false, features = ["http-proto", "reqwest-client"] }
60-
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
61-
opentelemetry-semantic-conventions = "0.12.0"
62-
tracing = { version = "0.1.40", features = ["async-await", "log"] }
69+
opentelemetry = { version = "0.20.0", features = ["rt-tokio"], optional = true }
70+
tracing-opentelemetry = { version = "0.21.0", optional = true }
71+
opentelemetry-otlp = { version = "0.13.0", default-features = false, features = ["http-proto", "reqwest-client"], optional = true }
72+
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"], optional = true }
73+
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
74+
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }
6375

6476
# optional dependencies for electrum-discovery
6577
electrum-client = { version = "0.8", optional = true }

src/bin/electrs.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ use electrs::{
2121
signal::Waiter,
2222
};
2323

24+
#[cfg(feature = "otlp-tracing")]
25+
use electrs::otlp_trace;
26+
2427
#[cfg(feature = "liquid")]
2528
use electrs::elements::AssetRegistry;
2629
use electrs::metrics::MetricOpts;
@@ -148,10 +151,22 @@ fn run_server(config: Arc<Config>) -> Result<()> {
148151
Ok(())
149152
}
150153

151-
fn main() {
154+
fn main_() {
152155
let config = Arc::new(Config::from_args());
153156
if let Err(e) = run_server(config) {
154157
error!("server failed: {}", e.display_chain());
155158
process::exit(1);
156159
}
157160
}
161+
162+
#[cfg(feature = "no-otlp-tracing")]
163+
fn main() {
164+
main_();
165+
}
166+
167+
#[cfg(feature = "otlp-tracing")]
168+
#[tokio::main]
169+
async fn main() {
170+
let _tracing_guard = otlp_trace::init_tracing("electrs");
171+
main_()
172+
}

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ impl Config {
405405
stderrlog::Timestamp::Off
406406
});
407407
log.init().expect("logging initialization failed");
408+
408409
let config = Config {
409410
log,
410411
network_type,

0 commit comments

Comments
 (0)