Skip to content

Commit 346b111

Browse files
authored
Fix Sentry child span capture by binding Hub correctly (#12284)
The root cause was that `with_sentry_transaction()` created a new Hub with the transaction context, but then in `worker.rs` the code called `.bind_hub(Hub::current())` which bound the future to the original Hub instead of the new one. This meant all child tracing spans were attached to the wrong Hub that lacked the transaction context, so Sentry never saw them as children of the transaction. The fix moves the `.bind_hub(hub)` call inside `with_sentry_transaction()` so the callback future executes with the correct Hub that has the transaction, ensuring all child spans are properly associated with the parent transaction.
1 parent 0e6678a commit 346b111

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

crates/crates_io_worker/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::anyhow;
2-
use sentry_core::Hub;
2+
use sentry_core::{Hub, SentryFutureExt};
33
use std::any::Any;
44
use std::future::Future;
55
use std::panic::PanicHookInfo;
@@ -20,7 +20,7 @@ where
2020

2121
hub.configure_scope(|scope| scope.set_span(Some(tx.clone().into())));
2222

23-
let result = callback().await;
23+
let result = callback().bind_hub(hub).await;
2424

2525
tx.set_status(match result.is_ok() {
2626
true => sentry_core::protocol::SpanStatus::Ok,

crates/crates_io_worker/src/worker.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use diesel_async::pooled_connection::deadpool::Pool;
77
use diesel_async::scoped_futures::ScopedFutureExt;
88
use diesel_async::{AsyncConnection, AsyncPgConnection};
99
use futures_util::FutureExt;
10-
use sentry_core::{Hub, SentryFutureExt};
1110
use std::panic::AssertUnwindSafe;
1211
use std::sync::Arc;
1312
use std::time::Duration;
@@ -87,10 +86,7 @@ impl<Context: Clone + Send + Sync + 'static> Worker<Context> {
8786
.and_then(std::convert::identity)
8887
});
8988

90-
let result = future
91-
.instrument(span.clone())
92-
.bind_hub(Hub::current())
93-
.await;
89+
let result = future.instrument(span.clone()).await;
9490

9591
let _enter = span.enter();
9692
match result {

0 commit comments

Comments
 (0)