Skip to content

Commit eeb5d61

Browse files
committed
Don't extract the parent context if the span is disabled
1 parent 2a3ea45 commit eeb5d61

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/cli/src/server.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,17 @@ fn make_http_span<B>(req: &Request<B>) -> Span {
136136
span.record(USER_AGENT_ORIGINAL, user_agent);
137137
}
138138

139-
// Extract the parent span context from the request headers
140-
let parent_context = opentelemetry::global::get_text_map_propagator(|propagator| {
141-
let extractor = HeaderExtractor(req.headers());
142-
let context = opentelemetry::Context::new();
143-
propagator.extract_with_context(&context, &extractor)
144-
});
145-
139+
// In case the span is disabled by any of tracing layers, e.g. if `RUST_LOG`
140+
// is set to `warn`, `set_parent` will fail. So we only try to set the
141+
// parent context if the span is not disabled.
146142
if !span.is_disabled() {
143+
// Extract the parent span context from the request headers
144+
let parent_context = opentelemetry::global::get_text_map_propagator(|propagator| {
145+
let extractor = HeaderExtractor(req.headers());
146+
let context = opentelemetry::Context::new();
147+
propagator.extract_with_context(&context, &extractor)
148+
});
149+
147150
if let Err(err) = span.set_parent(parent_context) {
148151
tracing::error!(
149152
error = &err as &dyn std::error::Error,

0 commit comments

Comments
 (0)