Skip to content

Commit e42e322

Browse files
wprzytulahawkw
authored andcommitted
opentelemetry: fix on_event not respecting events' explicit parents (#2296)
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. Fixes: #2295 See #2295
1 parent e4d3e36 commit e42e322

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tracing-opentelemetry/src/layer.rs

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

0 commit comments

Comments
 (0)