From c78c5eaa5c56978019912b3703645b4fb5a61303 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 Nov 2025 12:32:34 +0100 Subject: [PATCH] Fix Sentry child span capture by binding Hub correctly 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. --- crates/crates_io_worker/src/util.rs | 4 ++-- crates/crates_io_worker/src/worker.rs | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/crates_io_worker/src/util.rs b/crates/crates_io_worker/src/util.rs index b960b1fbc8f..b001bb49219 100644 --- a/crates/crates_io_worker/src/util.rs +++ b/crates/crates_io_worker/src/util.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use sentry_core::Hub; +use sentry_core::{Hub, SentryFutureExt}; use std::any::Any; use std::future::Future; use std::panic::PanicHookInfo; @@ -20,7 +20,7 @@ where hub.configure_scope(|scope| scope.set_span(Some(tx.clone().into()))); - let result = callback().await; + let result = callback().bind_hub(hub).await; tx.set_status(match result.is_ok() { true => sentry_core::protocol::SpanStatus::Ok, diff --git a/crates/crates_io_worker/src/worker.rs b/crates/crates_io_worker/src/worker.rs index 5f5c1fdd696..52f1d61ee50 100644 --- a/crates/crates_io_worker/src/worker.rs +++ b/crates/crates_io_worker/src/worker.rs @@ -7,7 +7,6 @@ use diesel_async::pooled_connection::deadpool::Pool; use diesel_async::scoped_futures::ScopedFutureExt; use diesel_async::{AsyncConnection, AsyncPgConnection}; use futures_util::FutureExt; -use sentry_core::{Hub, SentryFutureExt}; use std::panic::AssertUnwindSafe; use std::sync::Arc; use std::time::Duration; @@ -87,10 +86,7 @@ impl Worker { .and_then(std::convert::identity) }); - let result = future - .instrument(span.clone()) - .bind_hub(Hub::current()) - .await; + let result = future.instrument(span.clone()).await; let _enter = span.enter(); match result {