From 8f82d0da926b91980ff6f002d728611a3eca2c58 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 8 Jan 2026 09:42:06 -0500 Subject: [PATCH] Create an OpenTelemetry link instead of setting parent The opentelemetry docs specifically call out our use-case (queueing an asynchronous task) as a use case for links: https://opentelemetry.io/docs/concepts/signals/traces/#span-links --- src/worker.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/worker.rs b/src/worker.rs index b28ce49..eb88a9e 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -287,14 +287,16 @@ impl Worker { attempt = task.attempt, ); - // Extract and set parent trace context from headers (for distributed tracing) + // Extract and add a trace link to the context from headers (for distributed tracing) + // We don't set the parent, since a task can be executed multiple times + // long after the original span from headers (e.g. an autopilot-api HTTP request) + // finishes. #[cfg(feature = "telemetry")] if let Some(ref headers) = task.headers { + use opentelemetry::trace::TraceContextExt; use tracing_opentelemetry::OpenTelemetrySpanExt; let parent_cx = crate::telemetry::extract_trace_context(headers); - if let Err(e) = span.set_parent(parent_cx) { - tracing::error!("Failed to update OpenTelemetry span {e:?}"); - } + span.add_link(parent_cx.span().span_context().clone()); } Self::execute_task_inner(