Skip to content

Commit 248ee2d

Browse files
committed
layer: on_event respects event's explicit parent
One can want to have an event added from outside context of a span, especially in an async code (e.g. between polls of the future, or between polling multiple futures instrumented with that span). Then it is expected that the event will be attached indeed to the span specified as the parent and not the contextual one.
1 parent f09bc43 commit 248ee2d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tracing-opentelemetry/src/subscriber.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ where
620620
/// [`ERROR`]: tracing::Level::ERROR
621621
/// [`Error`]: opentelemetry::trace::StatusCode::Error
622622
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, C>) {
623-
// Ignore events that are not in the context of a span
624-
if let Some(span) = ctx.lookup_current() {
623+
// Ignore events that have no explicit parent set *and* are not in the context of a span
624+
if let Some(span) = ctx.event_span(event) {
625625
// Performing read operations before getting a write lock to avoid a deadlock
626626
// See https://github.com/tokio-rs/tracing/issues/763
627627
#[cfg(feature = "tracing-log")]

0 commit comments

Comments
 (0)