Adapt to the new tracing-opentelemetry API
This commit is contained in:
@@ -143,7 +143,12 @@ fn make_http_span<B>(req: &Request<B>) -> Span {
|
||||
propagator.extract_with_context(&context, &extractor)
|
||||
});
|
||||
|
||||
span.set_parent(parent_context);
|
||||
if let Err(err) = span.set_parent(parent_context) {
|
||||
tracing::error!(
|
||||
error = &err as &dyn std::error::Error,
|
||||
"Failed to set parent context on span"
|
||||
);
|
||||
}
|
||||
|
||||
span
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
|
||||
use console::{Color, Style};
|
||||
use opentelemetry::{
|
||||
TraceId,
|
||||
trace::{SamplingDecision, TraceContextExt},
|
||||
};
|
||||
use opentelemetry::TraceId;
|
||||
use tracing::{Level, Subscriber};
|
||||
use tracing_opentelemetry::OtelData;
|
||||
use tracing_subscriber::{
|
||||
@@ -131,31 +128,14 @@ where
|
||||
// If we have a OTEL span, we can add the trace ID to the end of the log line
|
||||
if let Some(span) = ctx.lookup_current()
|
||||
&& let Some(otel) = span.extensions().get::<OtelData>()
|
||||
&& let Some(trace_id) = otel.trace_id()
|
||||
&& trace_id != TraceId::INVALID
|
||||
{
|
||||
let parent_cx_span = otel.parent_cx.span();
|
||||
let sc = parent_cx_span.span_context();
|
||||
|
||||
// Check if the span is sampled, first from the span builder,
|
||||
// then from the parent context if nothing is set there
|
||||
if otel
|
||||
.builder
|
||||
.sampling_result
|
||||
.as_ref()
|
||||
.map_or(sc.is_sampled(), |r| {
|
||||
r.decision == SamplingDecision::RecordAndSample
|
||||
})
|
||||
{
|
||||
// If it is the root span, the trace ID will be in the span builder. Else, it
|
||||
// will be in the parent OTEL context
|
||||
let trace_id = otel.builder.trace_id.unwrap_or(sc.trace_id());
|
||||
if trace_id != TraceId::INVALID {
|
||||
let label = Style::new()
|
||||
.italic()
|
||||
.force_styling(ansi)
|
||||
.apply_to("trace.id");
|
||||
write!(&mut writer, " {label}={trace_id}")?;
|
||||
}
|
||||
}
|
||||
let label = Style::new()
|
||||
.italic()
|
||||
.force_styling(ansi)
|
||||
.apply_to("trace.id");
|
||||
write!(&mut writer, " {label}={trace_id}")?;
|
||||
}
|
||||
|
||||
writeln!(&mut writer)
|
||||
|
||||
Reference in New Issue
Block a user