Skip to content

Commit

Permalink
fix: trace_id extraction for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fhsgoncalves committed Feb 10, 2024
1 parent 5b433d0 commit 141290a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ fn lookup_trace_info<S>(span_ref: &SpanRef<S>) -> Option<TraceInfo>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
span_ref.extensions().get::<OtelData>().map(|o| TraceInfo {
trace_id: o.parent_cx.span().span_context().trace_id().into(),
span_id: o.builder.span_id.unwrap_or(SpanId::INVALID).into(),
span_ref.extensions().get::<OtelData>().map(|o| {
let trace_id = if o.parent_cx.has_active_span() {
o.parent_cx.span().span_context().trace_id()
} else {
o.builder.trace_id.unwrap_or(TraceId::INVALID)
};
TraceInfo {
trace_id: trace_id.into(),
span_id: o.builder.span_id.unwrap_or(SpanId::INVALID).into(),
}
})
}

Expand Down

0 comments on commit 141290a

Please sign in to comment.