---
title: "Trace the OpenAI Agents SDK"
description: "Trace OpenAI Agents SDK runs, handoffs and tool calls in Python with the OpenInference instrumentor."
sidebar:
  label: "OpenAI Agents SDK"
seo:
  title: "Trace the OpenAI Agents SDK | Judgment Docs"
  description: "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.

```bash
pip install judgeval openai-agents openinference-instrumentation-openai-agents
```

```python title="agent.py"
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.

{/* SCREENSHOT: Traces view, one OpenAI Agents SDK run with a handoff showing two agent spans and a function tool span, dark mode */}

## 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:

```python
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 `pip` can't find the package, you typed `openai-agents-sdk`. Install `openai-agents`.
- If you see two spans per model call, you also wrapped an `OpenAI` client with `wrap()` 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.

