Skip to content

Commit

Permalink
opentelemetry: fix on_event not respecting events' explicit parents (
Browse files Browse the repository at this point in the history
…tokio-rs#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: tokio-rs#2295

See tokio-rs#2295
  • Loading branch information
wprzytula authored and kaffarell committed May 22, 2024
1 parent 5777f1f commit 00fb608
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tracing-opentelemetry/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ where
/// [`ERROR`]: tracing::Level::ERROR
/// [`Error`]: opentelemetry::trace::StatusCode::Error
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
// Ignore events that are not in the context of a span
if let Some(span) = ctx.lookup_current() {
// Ignore events that have no explicit parent set *and* are not in the context of a span
if let Some(span) = ctx.event_span(event) {
// Performing read operations before getting a write lock to avoid a deadlock
// See https://github.com/tokio-rs/tracing/issues/763
#[cfg(feature = "tracing-log")]
Expand Down

0 comments on commit 00fb608

Please sign in to comment.