8000 worker: Fix tracing instrumentation (#11358) · rust-lang/crates.io@a3d296b · GitHub
[go: up one dir, main page]

Skip to content

Commit a3d296b

Browse files
authored
worker: Fix tracing instrumentation (#11358)
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.
1 parent bf66ba9 commit a3d296b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/crates_io_worker/src/worker.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::panic::AssertUnwindSafe;
1212
use std::sync::Arc;
1313
use std::time::Duration;
1414
use tokio::time::sleep;
15-
use tracing::{debug, error, info_span, warn};
15+
use tracing::{Instrument, debug, error, info_span, warn};
1616

1717
pub struct Worker<Context> {
1818
pub(crate) connection_pool: Pool<AsyncPgConnection>,
@@ -70,7 +70,6 @@ impl<Context: Clone + Send + Sync + 'static> Worker<Context> {
7070
};
7171

7272
let span = info_span!("job", job.id = %job.id, job.typ = %job.job_type);
73-
let _enter = span.enter();
7473

7574
let job_id = job.id;
7675
debug!("Running job…");
@@ -88,9 +87,15 @@ impl<Context: Clone + Send + Sync + 'static> Worker<Context> {
8887
.and_then(std::convert::identity)
8988
});
9089

91-
match future.bind_hub(Hub::current()).await {
90+
let result = future
91+
.instrument(span.clone())
92+
.bind_hub(Hub::current())
93+
.await;
94+
95+
let _enter = span.enter();
96+
match result {
9297
Ok(_) => {
93-
debug!("Deleting successful job…");
98+
warn!("Deleting successful job…");
9499
storage::delete_successful_job(conn, job_id).await?
95100
}
96101
Err(error) => {

0 commit comments

Comments
 (0)
0