Skip to content

Stop starting replica traces in the OpenAI Agents OTel interceptor - #1861

Closed
DABH wants to merge 1 commit into
mainfrom
otel-bridge-no-replica-registration
Closed

DABH wants to merge 1 commit into
mainfrom
otel-bridge-no-replica-registration

Conversation

@DABH

@DABH DABH commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

OpenAIAgentsPlugin(use_otel_instrumentation=True) exported temporal:startWorkflow and temporal:startActivity spans whose parent was never exported, so model and tool subtrees rendered detached in Phoenix, and a client running in the worker process lost its root span. The interceptor recreated and started the caller's Agents SDK trace and span on the worker; OpenInference registered these never-finished copies under the caller's IDs, displacing the caller's entries and leaking one per task.

The receiving side now restores them without starting them and attaches the propagated OTel span context as current, so spans created there parent to the caller's span. The start_traces flag only served the copies and is removed; the seeding methods on TemporalIdGenerator are now unused but left in place to keep this change small. A caller without an OTel span no longer gets a synthesized root on the worker.

A new single-process regression test with an activity tool fails on main. Two existing tests started the client trace before the worker had installed instrumentation and only passed because the copy stood in for the root; they now use tracing_context().

Fixes #1852

With use_otel_instrumentation=True the receiving side recreated the
caller's Agents SDK trace and span and started them, so OpenInference
registered never-finished copies under the caller's IDs. In a shared
process these displaced the caller's own spans, leaving
temporal:startWorkflow and temporal:startActivity spans with a parent
that was never exported and dropping the client's root span.

Restore the trace and span without starting them and attach the
propagated OTel span context as current so receiving-side spans parent
to the caller's span. Remove the now unused id seeding and start_traces
flag.

Fixes #1852
@DABH
DABH force-pushed the otel-bridge-no-replica-registration branch from a53ec68 to d25b184 Compare September 14, 2026 17:36
@DABH
DABH requested a balanced review from Copilot September 14, 2026 18:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The reconstructed parent always forces sampling instead of preserving the caller’s sampling decision.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates OpenAI Agents OTel propagation to avoid worker-side replica spans and detached trace trees.

Changes:

  • Restores propagated spans without starting copies.
  • Parents worker spans using propagated OTel context.
  • Adds single-process regression coverage and changelog notes.
File summaries
File Description
CHANGELOG.md Documents corrected span parenting.
temporalio/contrib/openai_agents/_trace_interceptor.py Removes replica-starting behavior.
temporalio/contrib/openai_agents/_otel_trace_interceptor.py Restores remote OTel parent context.
temporalio/contrib/openai_agents/_temporal_openai_agents.py Removes obsolete ID generator wiring.
tests/contrib/openai_agents/test_openai_tracing.py Updates setup and adds regression coverage.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

trace_id=otel_trace_id,
span_id=otel_span_id,
is_remote=True,
trace_flags=TraceFlags(TraceFlags.SAMPLED),
@DABH

DABH commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1856, which was opened first and fixes the same issue with the same approach (remote parent context instead of started replicas) plus trace flags/state propagation and root-context cleanup. Its regression test coverage is being folded into #1856.

@DABH DABH closed this Sep 14, 2026
@DABH
DABH deleted the otel-bridge-no-replica-registration branch September 14, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openai_agents OpenTelemetry tracing: detached spans and missing client root span when client and worker share a process

2 participants