Tracing

This SDK supports OpenAI Traces (traces=v1) compatible tracing.
Defaults
- Tracing is enabled by default.
- Each
Runner.Run()andRunner.Stream()call is wrapped in a trace namedAgent workflowunless you already have an active trace in thecontext.Context. - Spans are emitted for: agent, generation, function/tool, guardrail, and handoff.
Configuration
You can configure tracing per run via RunConfig:
TraceWorkflowName: workflow name (defaultAgent workflow)TraceID: override trace idTraceGroupID: optional grouping idTraceMetadata: optional metadata mapTraceEnabled: set tofalseto disable tracing for that runTraceIncludeSensitiveData: controls inclusion of potentially sensitive request/response/tool I/OTraceAPIKey: override export API key (useful for tracing non-OpenAI model calls while exporting to OpenAI Traces)
Environment variables
OPENAI_AGENTS_DISABLE_TRACING=1: disable tracing globallyOPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA=true|false: default sensitive-data behaviorOPENAI_API_KEY: used for trace export if no per-trace key is providedOPENAI_ORG_ID,OPENAI_PROJECT_ID: included as export headers when set
Custom exporters/processors
You can replace the global provider used by the SDK:
- Use
tracing.NewBackendSpanExporter()+tracing.NewBatchTracingProcessor(...)+tracing.NewDefaultTraceProvider(...) - Call
tracing.SetTraceProvider(...)to install it
Tracing
This SDK can emit OpenAI Traces (traces=v1) compatible traces and spans for Runner.Run and Runner.Stream.
Enable tracing export
Tracing is enabled by default unless disabled via environment variable or RunConfig.
To export traces to OpenAI, configure a trace provider with a batch processor and the OpenAI backend exporter:
exporter := tracing.NewBackendSpanExporter()
processor := tracing.NewBatchTracingProcessor(exporter)
provider := tracing.NewDefaultTraceProvider(processor)
tracing.SetTraceProvider(provider)
defer provider.Shutdown(context.Background())
Disabling tracing
- Global kill switch: set
OPENAI_AGENTS_DISABLE_TRACING=1 - Per-run: set
RunConfig.TraceEnabled = ptr(false)
If a trace already exists in the provided context, the runner will not create a new trace.
Workflow / trace / group / metadata
Use RunConfig fields to control trace metadata:
TraceWorkflowNameTraceID(optional; autogenerated if empty)TraceGroupIDTraceMetadata(map[string]any)
Sensitive data
By default, sensitive data is included. You can change defaults or override per-run:
- Global:
OPENAI_AGENTS_TRACE_INCLUDE_SENSITIVE_DATA=0 - Per-run:
RunConfig.TraceIncludeSensitiveData = ptr(false)
When disabled, spans will store "[REDACTED]" for request/response and tool arguments/outputs.