Repository navigation
Add a Worker-side tracingApiKey option to the TypeScript OpenAI Agents plugin - #215
Merged
campoy merged 2 commits intoOct 30, 2026
Conversation
…s plugin
A trace's export key is not carried across Temporal boundaries, because the
plugin's trace header is stored in Workflow history. So spans made in
Activities and Nexus handlers, and the Workflow spans of a trace started by a
Client with tracingApiKey, went out with the exporter's default key.
The new OpenAIAgentsPlugin option tracingApiKey resolves a key on the Worker
for those spans. The Activity and Nexus interceptors give the restored trace
the key, and the tracing sink gives it to Workflow traces and spans that have
no key of their own. A key a run sets with tracing: { apiKey } still applies
to its Workflow spans. Without the option nothing changes.
This was referenced Oct 27, 2026
campoy
marked this pull request as ready for review
October 29, 2026 19:26
brianstrauch
approved these changes
Oct 29, 2026
campoy
deleted the
fix/openai-agents-typescript-tracing-key-dropped-across-boundary
branch
October 30, 2026 15:14
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
OpenAIAgentsPluginhas a new optional Worker-side option,tracingApiKey, that gives a tracing key to spans that cross a Temporal boundary without one:tracingApiKey. Returningundefinedkeeps the exporter's default key.withRestoredAgentsTraceContextsets the key on the rebuiltTrace, so spans made in the Activity (the model'sgenerationspan, a tool body's spans,temporal:executeActivity) take it.listTools()andcallTool()spans take the key too. The resolver is held Worker-side, keyed by the Activity's context, and never goes into Activity arguments.tracing: { apiKey }stays on its Workflow spans when the run starts its own trace. Inside a client's trace the run joins that trace and the Agents SDK ignores the run's key, so those spans get the resolved key.TracingApiKeyResolverandTracingApiKeyContext, and a "Tracing keys per run" part in the README's "Tracing" section.API change: additive. Without
tracingApiKeythe plugin behaves as before.Replay and rollback: no Workflow-side behavior changes.
withRestoredAgentsTraceContextis shared with Workflow code, but Workflow code never passes the new argument; the resolver runs only in the Activity and Nexus interceptors (including the stateful MCP dedicated Worker's) and in the sink, on the Worker. The trace header, Activity inputs and History don't change, so histories replay on either version, and the previous release is a safe rollback.Why?
See #214. The
__openai_spanheader holds only the trace name and IDs, because it is stored in Event History and must not carry a credential. The receiving side rebuilt the trace without a key, so those spans went out with the Worker's default key: the Activity spans of a run with its own key, including thegenerationspan that holds the prompt, and every Workflow and Activity span of a Workflow started inside a keyed client trace. At OpenAI's ingest the key selects the account, so those spans landed in another account without any warning.Checklist
Closes [Bug] openai-agents (TypeScript): a run's or client trace's tracing key does not reach spans made past a Temporal boundary #214
How was this tested:
tracingApiKey gives spans that cross a Temporal boundary the key the Worker resolvesinsrc/__tests__/test-openai-agents.ts. It runs one Workflow with its own key, the same Workflow with its own key inside a keyed client trace, and a stateful MCP Workflow inside that trace, with a model and an MCP server that open spans. It checks the key of the Activity span, the run's own Workflow span (outside a client trace), the client trace's Workflow span (the run's key is ignored there), the stateful MCPconnectspan on the main Worker and thelistTools/callToolspans on the dedicated Worker, and the resolver's context.Nexus handler spans get the key from tracingApiKeyinsrc/__tests__/trace-interceptor.test.ts; no existing test covers the Worker's trace interceptors.main. With the option kept but the two lines that apply the key turned off, both tests fail:Activity span of a run with its own keygetsundefinedinstead of'sk-resolved-run', and the Nexus span getsundefined. With only the sink line turned off, the Workflow span in a keyed client trace getsundefinedinstead of'sk-resolved-trace'. With only the stateful MCP forwarding turned off, the dedicated Worker'slistToolsspan getsundefinedinstead of'sk-resolved-mcp'. With the change all pass.make sync,make lint(8 existing warnings, none in files this PR touches),make test(209 tests),make build,node ../_shared/smoke.mjsandscripts/ci/check_conventions.pypass.mainatc664a34and on this branch without the option. Withresolve(the option set) it exits 1 on 1.24.0 andmain, which ignore it, and 0 on this branch.OpenAITracingExporterposting to a loopback ingest, a run with its own key and a keyed client trace both export every item, including thegenerationspan with the prompt, with their key when the option is set. Without it, the output matchesmain. (This was run before the stateful MCP fix; the stateful MCP spans are covered by the test above.)mainand on this branch (with the option set) replay on both withWorker.runReplayHistories, 2 of 2 each. A control Workflow with one extra agent run fails with[TMPRL1100].CI covers the other Node versions and platforms.
Any docs updates needed?
The README part, included here.
Related: #185 reports the same mechanism in the Python plugin. Its draft fix #186 refuses a trace's own key at Temporal boundaries instead (breaking, gated), and names a Worker-side key resolver as a possible separate, additive feature. This PR takes the resolver route for TypeScript: a refusal would break the Workflow-side part of a run's own key, which works today.
Not covered:
tracing: { apiKey }inside a trace a Client started is ignored by the Agents SDK; the resolver decides those spans' key.Open questions:
Draft while these questions are open.