Skip to content

Commit b8144c7

Browse files
declan-scaleclaude
andcommitted
fix(temporal): disable OpenAI Agents SDK trace exporter under Temporal 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>
1 parent 35fc4b8 commit b8144c7

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • src/agentex/lib/core/temporal/workers

src/agentex/lib/core/temporal/workers/worker.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ async def get_temporal_client(
112112

113113
has_openai_plugin = any(isinstance(p, OpenAIAgentsPlugin) for p in (plugins or []))
114114

115+
if has_openai_plugin:
116+
# Disable the OpenAI Agents SDK's built-in trace exporter. That exporter
117+
# is process-global and POSTs spans to api.openai.com/v1/traces. Under
118+
# Temporal the run's trace context does not survive the workflow->activity
119+
# hop, so spans created in activities have no active trace and are emitted
120+
# as NoOpSpans (trace_id="no-op"); the exporter then rejects every turn
121+
# with "Invalid 'data[0].trace_id': 'no-op'". We never want this exporter:
122+
# Agentex has its own SGP tracing pipeline (AsyncTracer / SGPTracingProcessor)
123+
# that is wholly separate from the OpenAI SDK trace provider.
124+
#
125+
# This must be an env var, not agents.set_tracing_disabled(): the plugin
126+
# installs a fresh TemporalTraceProvider at worker/client startup whose
127+
# `_disabled` is re-read from OPENAI_AGENTS_DISABLE_TRACING in __init__, so
128+
# any prior set_tracing_disabled() call is discarded. setdefault preserves
129+
# an explicit operator override (e.g. =0 to re-enable).
130+
os.environ.setdefault("OPENAI_AGENTS_DISABLE_TRACING", "1")
131+
115132
if has_openai_plugin and payload_codec is not None and data_converter is None:
116133
raise ValueError(
117134
"payload_codec passed as a kwarg alongside OpenAIAgentsPlugin would "

0 commit comments

Comments
 (0)