From 34220fab8441d6a9f361cb6aa1a2359e7e640b12 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 13 Jun 2025 19:55:02 +0200 Subject: [PATCH] worker: Fix tracing instrumentation For some reason only background jobs with the `#[instrumented]` annotation were receiving the `job.id` and `job.typ` fields from the parent span. This commit adjusts the `span` usage to not require the annotation and attach these fields for all background jobs. --- crates/crates_io_worker/src/worker.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/crates_io_worker/src/worker.rs b/crates/crates_io_worker/src/worker.rs index 149bc52ac5e..1e233ae8acd 100644 --- a/crates/crates_io_worker/src/worker.rs +++ b/crates/crates_io_worker/src/worker.rs @@ -12,7 +12,7 @@ use std::panic::AssertUnwindSafe; use std::sync::Arc; use std::time::Duration; use tokio::time::sleep; -use tracing::{debug, error, info_span, warn}; +use tracing::{Instrument, debug, error, info_span, warn}; pub struct Worker { pub(crate) connection_pool: Pool, @@ -70,7 +70,6 @@ impl Worker { }; let span = info_span!("job", job.id = %job.id, job.typ = %job.job_type); - let _enter = span.enter(); let job_id = job.id; debug!("Running job…"); @@ -88,9 +87,15 @@ impl Worker { .and_then(std::convert::identity) }); - match future.bind_hub(Hub::current()).await { + let result = future + .instrument(span.clone()) + .bind_hub(Hub::current()) + .await; + + let _enter = span.enter(); + match result { Ok(_) => { - debug!("Deleting successful job…"); + warn!("Deleting successful job…"); storage::delete_successful_job(conn, job_id).await? } Err(error) => {