Skip to content

Commit 12f5773

Browse files
authored
Create an OpenTelemetry link instead of setting parent (#53)
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
1 parent d1d50e8 commit 12f5773

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/worker.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,16 @@ impl Worker {
289289
otel.kind = "server",
290290
);
291291

292-
// Extract and set parent trace context from headers (for distributed tracing)
292+
// Extract and add a trace link to the context from headers (for distributed tracing)
293+
// We don't set the parent, since a task can be executed multiple times
294+
// long after the original span from headers (e.g. an autopilot-api HTTP request)
295+
// finishes.
293296
#[cfg(feature = "telemetry")]
294297
if let Some(ref headers) = task.headers {
298+
use opentelemetry::trace::TraceContextExt;
295299
use tracing_opentelemetry::OpenTelemetrySpanExt;
296300
let parent_cx = crate::telemetry::extract_trace_context(headers);
297-
if let Err(e) = span.set_parent(parent_cx) {
298-
tracing::error!("Failed to update OpenTelemetry span {e:?}");
299-
}
301+
span.add_link(parent_cx.span().span_context().clone());
300302
}
301303

302304
Self::execute_task_inner(

0 commit comments

Comments
 (0)