diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dc99f29..ecd463f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Improvements + +- With the `debug` option enabled, the SDK now logs a message when it drops a span because the span finished after its transaction was already sent. The `sentry-tracing` docs now explain how this can happen when a library keeps a clone of a `tracing` span ([#1367](https://github.com/getsentry/sentry-rust/pull/1367)). + ### Fixes - [`Transport::flush`](https://docs.rs/sentry-core/0.49.6/sentry_core/trait.Transport.html#method.flush) on an `Arc`-wrapped transport now flushes the inner transport, instead of returning `true` immediately ([#1390](https://github.com/getsentry/sentry-rust/pull/1390)). diff --git a/sentry-core/src/performance/mod.rs b/sentry-core/src/performance/mod.rs index 60ba6812..f34ca751 100644 --- a/sentry-core/src/performance/mod.rs +++ b/sentry-core/src/performance/mod.rs @@ -1301,6 +1301,15 @@ impl Span { } else if let Some(client) = inner.client.as_ref() { client.record_lost_data(&*span, ClientReportReason::BufferOverflow); } + } else if matches!(inner.tracing_state.finish_action(), FinishAction::Send { .. }) { + // The transaction was already sent, so there is nothing left to add this span to. + sentry_debug!( + "[Span] dropping span {} (op: {:?}, description: {:?}) because it finished \ + after its transaction was already sent", + span.span_id, + span.op, + span.description, + ); } }} } diff --git a/sentry-tracing/README.md b/sentry-tracing/README.md index 60bef431..86c77681 100644 --- a/sentry-tracing/README.md +++ b/sentry-tracing/README.md @@ -100,6 +100,13 @@ async fn handle_request(headers: std::collections::HashMap) { } ``` +### Spans finishing after their transaction + +A Sentry span finishes when its `tracing` span closes, which only happens once every handle to +the `tracing` span is dropped. If a library holds on to a clone, as `sqlx`'s SQLite driver does, +the span can close after its transaction was sent, and is then dropped. To avoid this, manually +start a Sentry span around the affected code. + ## Logs `LogLayer` sends events accepted by its filter as structured logs. Event fields become log diff --git a/sentry-tracing/src/lib.rs b/sentry-tracing/src/lib.rs index 924c01b0..8b06929d 100644 --- a/sentry-tracing/src/lib.rs +++ b/sentry-tracing/src/lib.rs @@ -91,6 +91,13 @@ //! } //! ``` //! +//! ## Spans finishing after their transaction +//! +//! A Sentry span finishes when its `tracing` span closes, which only happens once every handle to +//! the `tracing` span is dropped. If a library holds on to a clone, as `sqlx`'s SQLite driver does, +//! the span can close after its transaction was sent, and is then dropped. To avoid this, manually +//! start a Sentry span around the affected code. +//! //! # Logs //! //! `LogLayer` sends events accepted by its filter as structured logs. Event fields become log