Shows the three tracing paths the Temporal OpenAI Agents integration supports. OpenAI Agents SDK tracing works across Client, Workflow, Activity, Nexus, and MCP boundaries, and Workflow replay does not duplicate spans.
The Worker selects a tracing mode (default custom):
npx ts-node src/tracing/worker.ts <mode> # mode: custom | openai | otel
# or set TRACING_MODE=<mode>All modes also set interceptorOptions: { addTemporalSpans: true }, which emits temporal:*
orchestration spans (Workflow starts, Activities, Signals, and so on) to whichever sink is active.
Registers a RecordingTracingProcessor (see src/tracing/recording-processor.ts) via addTraceProcessor.
It receives every trace and span lifecycle callback, so you can record, filter, or forward spans
anywhere. This is the mode exercised by the test.
Registers the upstream hosted exporter before constructing the plugin, so traces appear on the OpenAI dashboard:
addTraceProcessor(new BatchTraceProcessor(new OpenAITracingExporter()));Register this in the Worker process, not inside Workflow code.
Installs a replay-safe tracer provider from @temporalio/openai-agents/otel and enables
useOtelInstrumentation:
trace.setGlobalTracerProvider(createTracerProvider());
// plugin: interceptorOptions: { useOtelInstrumentation: true }createTracerProvider uses TemporalIdGenerator for replay-safe span/trace IDs. This mode requires
the optional peer dependency @opentelemetry/sdk-trace-base.
temporal server start-devRun these from the openai-agents/ root (run npm install there once first).
export OPENAI_API_KEY=sk-...
npx ts-node src/tracing/worker.ts customnpx ts-node src/tracing/client.ts "What is 42 plus 58?"The test runs offline with a FakeModelProvider. It registers a custom TracingProcessor, runs an
agent that calls a function tool, and asserts that agent and function spans were emitted.
npx mocha --exit --require ts-node/register --require source-map-support/register "src/tracing/mocha/*.test.ts"