Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions temporalio/contrib/openai_agents/_otel_trace_interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ def header_contents(self) -> dict[str, Any]:
otel_span = opentelemetry.trace.get_current_span()

if otel_span and otel_span.get_span_context().is_valid:
otel_span_id = otel_span.get_span_context().span_id
span_context = otel_span.get_span_context()
return {
**super().header_contents(),
"otelSpanId": otel_span_id,
"otelSpanId": span_context.span_id,
"otelTraceId": span_context.trace_id,
}
else:
return super().header_contents()
Expand All @@ -63,6 +64,12 @@ def context_from_header(
if span_info is None:
return
otel_span_id = span_info.get("otelSpanId")
otel_trace_id = span_info.get("otelTraceId")

# Seed the trace id before the trace is reconstructed so the workflow's root
# OTEL span shares the caller's trace id rather than generating a new one.
if otel_trace_id and self._otel_id_generator:
self._otel_id_generator.seed_trace_id(otel_trace_id)

# If only a trace was propagated from the caller, we need to seed for trace context
if otel_span_id and self._otel_id_generator and span_info.get("spanId") is None:
Expand Down
Loading