Skip to content

Commit acb5290

Browse files
committed
Adapt to the new tracing-opentelemetry API
1 parent 53ab31d commit acb5290

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

crates/cli/src/server.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ fn make_http_span<B>(req: &Request<B>) -> Span {
143143
propagator.extract_with_context(&context, &extractor)
144144
});
145145

146-
span.set_parent(parent_context);
146+
if let Err(err) = span.set_parent(parent_context) {
147+
tracing::error!(
148+
error = &err as &dyn std::error::Error,
149+
"Failed to set parent context on span"
150+
);
151+
}
147152

148153
span
149154
}

crates/context/src/fmt.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
// Please see LICENSE files in the repository root for full details.
55

66
use console::{Color, Style};
7-
use opentelemetry::{
8-
TraceId,
9-
trace::{SamplingDecision, TraceContextExt},
10-
};
7+
use opentelemetry::TraceId;
118
use tracing::{Level, Subscriber};
129
use tracing_opentelemetry::OtelData;
1310
use tracing_subscriber::{
@@ -131,31 +128,14 @@ where
131128
// If we have a OTEL span, we can add the trace ID to the end of the log line
132129
if let Some(span) = ctx.lookup_current()
133130
&& let Some(otel) = span.extensions().get::<OtelData>()
131+
&& let Some(trace_id) = otel.trace_id()
132+
&& trace_id != TraceId::INVALID
134133
{
135-
let parent_cx_span = otel.parent_cx.span();
136-
let sc = parent_cx_span.span_context();
137-
138-
// Check if the span is sampled, first from the span builder,
139-
// then from the parent context if nothing is set there
140-
if otel
141-
.builder
142-
.sampling_result
143-
.as_ref()
144-
.map_or(sc.is_sampled(), |r| {
145-
r.decision == SamplingDecision::RecordAndSample
146-
})
147-
{
148-
// If it is the root span, the trace ID will be in the span builder. Else, it
149-
// will be in the parent OTEL context
150-
let trace_id = otel.builder.trace_id.unwrap_or(sc.trace_id());
151-
if trace_id != TraceId::INVALID {
152-
let label = Style::new()
153-
.italic()
154-
.force_styling(ansi)
155-
.apply_to("trace.id");
156-
write!(&mut writer, " {label}={trace_id}")?;
157-
}
158-
}
134+
let label = Style::new()
135+
.italic()
136+
.force_styling(ansi)
137+
.apply_to("trace.id");
138+
write!(&mut writer, " {label}={trace_id}")?;
159139
}
160140

161141
writeln!(&mut writer)

0 commit comments

Comments
 (0)