|
4 | 4 | // Please see LICENSE files in the repository root for full details. |
5 | 5 |
|
6 | 6 | use console::{Color, Style}; |
7 | | -use opentelemetry::{ |
8 | | - TraceId, |
9 | | - trace::{SamplingDecision, TraceContextExt}, |
10 | | -}; |
| 7 | +use opentelemetry::TraceId; |
11 | 8 | use tracing::{Level, Subscriber}; |
12 | 9 | use tracing_opentelemetry::OtelData; |
13 | 10 | use tracing_subscriber::{ |
@@ -131,31 +128,14 @@ where |
131 | 128 | // If we have a OTEL span, we can add the trace ID to the end of the log line |
132 | 129 | if let Some(span) = ctx.lookup_current() |
133 | 130 | && let Some(otel) = span.extensions().get::<OtelData>() |
| 131 | + && let Some(trace_id) = otel.trace_id() |
| 132 | + && trace_id != TraceId::INVALID |
134 | 133 | { |
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}")?; |
159 | 139 | } |
160 | 140 |
|
161 | 141 | writeln!(&mut writer) |
|
0 commit comments