openai-agents library via the OpenAITracingSGPProcessor. This processor automatically captures detailed traces from your AI agent runs, translating events from the agent’s lifecycle into SGP traces and spans.
This provides deep visibility into your agent’s execution, including tool calls and model invocations, without requiring manual instrumentation.
This integration requires the
openai-agents package. The processor will raise an ImportError if the package is not installed.How it Works
TheOpenAITracingSGPProcessor hooks into the openai-agents tracing system. You register it once, and it listens for lifecycle events, handling the translation to SGP tracing objects automatically.
-
Trace Management:
- When an agent run starts,
on_trace_startcreates a corresponding SGP trace with the typeAGENT_WORKFLOW. The root span of this trace is stored internally. - When the run ends,
on_trace_endfinds the stored root span and marks it as complete.
- When an agent run starts,
-
Span Management:
- As the agent executes,
on_span_startfires for each new operation. It creates a new SGP span, linking it to the correct parent (either another span or the root trace). - It uses the
openai_span_type_maphelper to convert the agent’s span type (e.g., “function”, “generation”) into an SGPSpanType(e.g., “CODE_EXECUTION”, “COMPLETION”). - When the operation finishes,
on_span_endpopulates the span’sinput,output, andmetadatausing helper functions that parse the data from the agent. If the agent reports an error, it’s recorded on the span.
- As the agent executes,
Usage Example
To use the processor, you must initialize SGP tracing and then register an instance ofOpenAITracingSGPProcessor with the openai-agents library.

