tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.14k stars 671 forks source link

subscriber: fix parent span resolution in json format #2978

Open mladedav opened 1 month ago

mladedav commented 1 month ago

Motivation

Closes #2973

When emitting json events, parents were always taken from context if they were not explicitly set. This included cases where parent was explicitly set to None.

Solution

The code now checks whether the event's parent is root (i.e. the event is not inside a span) and if so, no span is included.

Span is also not looked up now in SerializableContext where we already have the current span so we can call scope on it directly. This lead to it being structurally identical to SerializableSpan, but we need a different implementation for Serialize so the two can live next to each other.