From b8144c79c899b3990654ddff53ba84f0e0acf429 Mon Sep 17 00:00:00 2001 From: Declan Brady Date: Tue, 16 Jun 2026 19:41:14 -0400 Subject: [PATCH] fix(temporal): disable OpenAI Agents SDK trace exporter under Temporal workers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/agentex/lib/core/temporal/workers/worker.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/agentex/lib/core/temporal/workers/worker.py b/src/agentex/lib/core/temporal/workers/worker.py index 253b6759f..0ce96c9fb 100644 --- a/src/agentex/lib/core/temporal/workers/worker.py +++ b/src/agentex/lib/core/temporal/workers/worker.py @@ -112,6 +112,23 @@ async def get_temporal_client( has_openai_plugin = any(isinstance(p, OpenAIAgentsPlugin) for p in (plugins or [])) + if has_openai_plugin: + # Disable the OpenAI Agents SDK's built-in trace exporter. That exporter + # is process-global and 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 "Invalid 'data[0].trace_id': 'no-op'". We never want this exporter: + # Agentex has its own SGP tracing pipeline (AsyncTracer / SGPTracingProcessor) + # that is wholly separate from the OpenAI SDK trace provider. + # + # This must be an env var, not agents.set_tracing_disabled(): the plugin + # installs a fresh TemporalTraceProvider at worker/client startup whose + # `_disabled` is re-read from OPENAI_AGENTS_DISABLE_TRACING in __init__, so + # any prior set_tracing_disabled() call is discarded. setdefault preserves + # an explicit operator override (e.g. =0 to re-enable). + os.environ.setdefault("OPENAI_AGENTS_DISABLE_TRACING", "1") + if has_openai_plugin and payload_codec is not None and data_converter is None: raise ValueError( "payload_codec passed as a kwarg alongside OpenAIAgentsPlugin would "