Trace the OpenAI Agents SDK
Trace OpenAI Agents SDK runs, handoffs and tool calls in Python with the OpenInference instrumentor.
The OpenAI Agents SDK (openai-agents on PyPI, imported as agents) has its own tracing system. The OpenInference instrumentor converts those traces into OpenTelemetry spans, and Tracer.registerOTELInstrumentation sends them to Judgment.
pip install judgeval openai-agents openinference-instrumentation-openai-agents
from agents import Agent, Runner, function_tool
from judgeval import Tracer
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
Tracer.init(project_name="lunch-order-agent")
Tracer.registerOTELInstrumentation(OpenAIAgentsInstrumentor())
@function_tool
def check_catering_capacity(restaurant: str, headcount: int) -> bool:
"""Check whether a restaurant can cater for this many people."""
return restaurant == "Olive & Thyme"
agent = Agent(
name="Lunch order agent",
instructions="Help the user order lunch for their office.",
model="gpt-5.2",
tools=[check_catering_capacity],
)
result = Runner.run_sync(agent, "order me mediterranean food to feed 30 hungry engineers")
print(result.final_output)
Tracer.force_flush()
Each run shows up as one trace: an agent span for each agent that ran (including agents reached through a handoff), with model calls and tool calls nested under it.
Keep OpenAI’s own trace viewer
By default the instrumentor replaces the Agents SDK’s trace processors, so traces stop going to OpenAI’s dashboard. To send to both, call the instrumentor yourself with exclusive_processor=False and Judgment’s provider:
from judgeval import JudgmentTracerProvider, Tracer
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor
Tracer.init(project_name="lunch-order-agent")
OpenAIAgentsInstrumentor().instrument(
tracer_provider=JudgmentTracerProvider.get_instance(),
exclusive_processor=False,
)
If something looks wrong
- If
pipcan’t find the package, you typedopenai-agents-sdk. Installopenai-agents. - If you see two spans per model call, you also wrapped an
OpenAIclient withwrap()or registered an OpenAI instrumentor. The Agents SDK instrumentor already records model calls. - If nothing reaches Judgment from a short script, call
Tracer.force_flush()before the process exits.