Skip to content

fix(temporal): disable OpenAI Agents SDK trace exporter under Temporal workers#403

Open
declan-scale wants to merge 1 commit into
nextfrom
declan-scale/disable-openai-sdk-tracing-under-temporal
Open

fix(temporal): disable OpenAI Agents SDK trace exporter under Temporal workers#403
declan-scale wants to merge 1 commit into
nextfrom
declan-scale/disable-openai-sdk-tracing-under-temporal

Conversation

@declan-scale

@declan-scale declan-scale commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Agents running under the Temporal OpenAIAgentsPlugin flood worker logs with, on every turn:

No active trace. Make sure to start a trace with `trace()` first Returning NoOpSpan.
Tracing client error 400: Invalid 'data[0].trace_id': 'no-op'. Expected an ID that begins with 'trace_'.

The OpenAI Agents SDK registers a process-global BackendSpanExporter that POSTs spans to api.openai.com/v1/traces. Under Temporal, the run's trace context does not survive the workflow→activity hop, so spans created in activities have no active trace and come out as NoOpSpans (trace_id="no-op"). The exporter then 400s on every turn and runs a failing background export thread.

Agentex never uses this exporter — it has its own SGP tracing pipeline (AsyncTracer / SGPTracingProcessor), wholly separate from the OpenAI SDK trace provider.

Fix

In get_temporal_client, when an OpenAIAgentsPlugin is present, set OPENAI_AGENTS_DISABLE_TRACING=1 (via setdefault, so an explicit operator override is preserved).

Why the env var (and not set_tracing_disabled())

The plugin installs a fresh TemporalTraceProvider at worker/client startup. Its __init__ (via DefaultTraceProvider) re-reads _disabled from OPENAI_AGENTS_DISABLE_TRACING — so any prior agents.set_tracing_disabled(True) is discarded. The env var is the only mechanism that survives the provider swap. Verified:

env=1     -> DefaultTraceProvider()._disabled = True
env unset -> DefaultTraceProvider()._disabled = False

With _disabled=True, create_trace/create_span short-circuit to NoOp before the "No active trace" log and before any processor dispatch — so no spans are created and nothing is exported to OpenAI. SGP tracing is unaffected (separate pipeline).

Testing

  • ruff check clean on the changed file.
  • mypy error count unchanged (21 → 21, all pre-existing no-untyped-call/missing-import); no new errors.
  • Runtime-verified the env var disables a fresh DefaultTraceProvider (the base of TemporalTraceProvider).

🤖 Generated with Claude Code

Greptile Summary

This PR disables OpenAI Agents SDK tracing when Temporal workers use the OpenAI Agents plugin. It changes:

  • Adds an OPENAI_AGENTS_DISABLE_TRACING default in the worker Temporal client helper.
  • Applies the setting only when an OpenAIAgentsPlugin is present.
  • Preserves explicit operator overrides by using setdefault.

Confidence Score: 3/5

This is close, but I would fix this before merging.

  • The worker path gets the new tracing disable behavior.
  • The ACP/client Temporal helper still skips the same environment setting.
  • ACP processes using OpenAIAgentsPlugin can keep the exporter enabled and still hit the noisy trace export path.

src/agentex/lib/core/clients/temporal/utils.py should mirror the worker helper behavior.

T-Rex T-Rex Logs

What T-Rex did

  • Identified that worker.py sets the OPENAI_AGENTS_DISABLE_TRACING environment variable inside the has_openai_plugin block.
  • Found that utils.py detects has_openai_plugin but does not set a corresponding environment variable in its function.
  • Traced the Temporal client creation path through TemporalClient.create, confirming it is an active client creation path.
  • Attempted a targeted runtime repro script but execution was blocked due to dependency constraints.
  • Compared sources and observed that the worker path and ACP/client path behave differently for the same plugin configuration.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/agentex/lib/core/temporal/workers/worker.py Adds the OpenAI Agents tracing disable for the worker-side Temporal client helper.
src/agentex/lib/core/clients/temporal/utils.py The parallel ACP/client Temporal helper still lacks the tracing disable behavior.

Comments Outside Diff (1)

  1. src/agentex/lib/core/clients/temporal/utils.py, line 124 (link)

    P1 Mirror tracing disable

    The ACP/client helper has the same OpenAIAgentsPlugin detection path as the worker helper, but it never sets OPENAI_AGENTS_DISABLE_TRACING. TemporalClient.create() passes configured plugins through this helper, so an ACP process using TemporalACPConfig(plugins=[OpenAIAgentsPlugin(...)]) can still leave the OpenAI Agents SDK exporter enabled and keep producing the trace export errors this PR is meant to stop. Please mirror the worker-side setdefault("OPENAI_AGENTS_DISABLE_TRACING", "1") behavior here as well.

    Artifacts

    Repro attempt output and source analysis summary

    • Keeps the command output available without making the summary code-heavy.

    View artifacts

    T-Rex Ran code and verified through T-Rex

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agentex/lib/core/clients/temporal/utils.py
    Line: 124
    
    Comment:
    **Mirror tracing disable**
    
    The ACP/client helper has the same `OpenAIAgentsPlugin` detection path as the worker helper, but it never sets `OPENAI_AGENTS_DISABLE_TRACING`. `TemporalClient.create()` passes configured plugins through this helper, so an ACP process using `TemporalACPConfig(plugins=[OpenAIAgentsPlugin(...)])` can still leave the OpenAI Agents SDK exporter enabled and keep producing the trace export errors this PR is meant to stop. Please mirror the worker-side `setdefault("OPENAI_AGENTS_DISABLE_TRACING", "1")` behavior here as well.
    
    How can I resolve this? If you propose a fix, please make it concise.

    Fix in Claude Code

Fix All in Claude Code

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/agentex/lib/core/clients/temporal/utils.py:124
**Mirror tracing disable**

The ACP/client helper has the same `OpenAIAgentsPlugin` detection path as the worker helper, but it never sets `OPENAI_AGENTS_DISABLE_TRACING`. `TemporalClient.create()` passes configured plugins through this helper, so an ACP process using `TemporalACPConfig(plugins=[OpenAIAgentsPlugin(...)])` can still leave the OpenAI Agents SDK exporter enabled and keep producing the trace export errors this PR is meant to stop. Please mirror the worker-side `setdefault("OPENAI_AGENTS_DISABLE_TRACING", "1")` behavior here as well.

Reviews (1): Last reviewed commit: "fix(temporal): disable OpenAI Agents SDK..." | Re-trigger Greptile

…l workers

The OpenAI Agents SDK registers a process-global BackendSpanExporter that POSTs
spans to api.openai.com/v1/traces. Under Temporal the run's trace context does
not survive the workflow->activity hop, so spans created in activities have no
active trace and are emitted as NoOpSpans (trace_id="no-op"). The exporter then
rejects every turn with 400 "Invalid 'data[0].trace_id': 'no-op'", flooding
worker logs and running a failing background export thread.

Agentex never uses this exporter — it has its own SGP tracing pipeline
(AsyncTracer / SGPTracingProcessor), wholly separate from the OpenAI SDK trace
provider. Disable it whenever an OpenAIAgentsPlugin is present.

Must be the OPENAI_AGENTS_DISABLE_TRACING env var, not agents.set_tracing_disabled():
the plugin installs a fresh TemporalTraceProvider at startup whose `_disabled`
is re-read from that env var in __init__, so a prior set_tracing_disabled() call
is discarded (verified). setdefault preserves an explicit operator override.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@declan-scale declan-scale changed the base branch from main to next June 16, 2026 23:45
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.

1 participant