Skip to content

Commit 72be0dc

Browse files
author
Fergus Dixon
committed
rewrite preference of trace ID
1 parent 0edb571 commit 72be0dc

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/formatter.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ where
4545
S: Subscriber + for<'a> LookupSpan<'a>,
4646
{
4747
span_ref.extensions().get::<OtelData>().map(|o| {
48-
let parent_id = o.parent_cx.span().span_context().trace_id();
49-
let trace_id = o.builder.trace_id.unwrap_or(parent_id);
48+
// If the parent ID is empty/0 - then fall back to the builder's ID
49+
let parent_span_cx = o.parent_cx.span();
50+
51+
let trace_id = if parent_span_cx.span_context().trace_id() != TraceId::INVALID {
52+
parent_span_cx.span_context().trace_id()
53+
} else {
54+
o.builder.trace_id.unwrap_or(TraceId::INVALID)
55+
};
5056
TraceInfo {
5157
trace_id: trace_id.into(),
5258
span_id: o.builder.span_id.unwrap_or(SpanId::INVALID).into(),

0 commit comments

Comments
 (0)