Docs
OpenAI Agents Integration

OpenAI Agents Integration

Map OpenAI Agents SDK traces, spans, processors, hooks, and function schemas into AITracer.

AITracer can mirror OpenAI Agents SDK tracing into local tamper-evident records.

The goal is not to replace provider-native tracing.

It preserves OpenAI tracing while adding:

  • local governance controls
  • trace persistence
  • verification workflows
  • tamper detection
  • long-term audit storage

This allows teams to maintain provider observability while creating independent execution records inside AITracer.


Integration workflow

Rendering diagram...

Core tracing surface

AITracer integrates with the OpenAI Agents SDK tracing layer through:

  • tracing
  • TracingConfig
  • TraceCtxManager
  • TraceProvider
  • TracingProcessor
  • add_trace_processor(...)
  • set_trace_processors(...)
  • set_tracing_disabled(...)
  • set_tracing_export_api_key(...)

These components allow AITracer to attach its own processing layer without disrupting OpenAI's native trace pipeline.


Trace and Span Mapping

AITracer maps OpenAI tracing concepts into internal execution records.

Trace metadata

  • workflow name
  • trace ID
  • group ID
  • metadata
  • start timestamps
  • finish timestamps
  • export metadata

Span metadata

  • span ID
  • parent span ID
  • span data
  • errors
  • timestamps
  • trace relationships

Supported span types

  • agent spans
  • custom spans
  • function spans
  • generation spans
  • guardrail spans
  • handoff spans
  • MCP tool spans
  • response spans
  • speech spans
  • transcription spans

Lifecycle Hooks

HookAITracer Role
on_llm_startCreate pending execution record
on_llm_endCapture token, latency, response, and cost metadata
on_tool_startTrack tool execution start
on_tool_endTrack tool execution completion
on_trace_startCreate trace-level verification metadata
on_trace_endFinalize trace records for storage
force_flushWrite buffered audit records
shutdownEnsure graceful processor shutdown

  1. Keep the default OpenAI exporter enabled
  2. Add a custom local mirror processor using add_trace_processor(...)
  3. Use stable workflow_name values
  4. Use stable group_id values for conversations or tasks
  5. Disable sensitive trace data in shared environments
  6. Preserve local canonical records for verification workflows
trace_include_sensitive_data=False

Minimal Integration Example

from agents import trace, custom_span, function_span
from agents import add_trace_processor
from agents.tracing import TracingProcessor
 
class LocalProcessor(TracingProcessor):
    def on_trace_start(self, trace): ...
    def on_trace_end(self, trace): ...
    def on_span_start(self, span): ...
    def on_span_end(self, span): ...
    def shutdown(self): ...
    def force_flush(self): ...
 
add_trace_processor(LocalProcessor())
 
with trace(
    "traceability_demo",
    metadata={"component": "aitracer"}
):
    with custom_span(
        "preflight",
        {"risk": "low"}
    ):
        pass
 
    with function_span(
        name="summarize",
        input="...",
        output="..."
    ):
        pass

Exact import paths and helper signatures may vary depending on the installed openai-agents SDK version.