Skip to content

Commit

Permalink
Fix resolving of the current span.
Browse files Browse the repository at this point in the history
  • Loading branch information
abusch committed Jul 16, 2023
1 parent 7f7bd98 commit 615ef4f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/formatting_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,17 @@ where
W: for<'a> MakeWriter<'a> + 'static,
{
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
// Lookup the current span, unless the event is a "root" event.
let current_span = if event.is_root() {
None
} else {
// Lookup the current span.
let current_span = if event.is_contextual() {
// If the event is _contextual_, ask the context for what it thinks the current span
// is.
// Events do not necessarily happen in the context of a span, hence lookup_current
// returns an `Option<SpanRef<_>>` instead of a `SpanRef<_>`.
ctx.lookup_current()
} else {
// Otherwise, the event is either a _root_ event, or the parent span was explicitly
// set.
event.parent().and_then(|id| ctx.span(id))
};

let mut event_visitor = JsonStorage::default();
Expand Down

0 comments on commit 615ef4f

Please sign in to comment.