> ## Documentation Index
> Fetch the complete documentation index at: https://www.botgauge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Trace OpenAI Agents with BotGauge

> Trace OpenAI Agents SDK runs with BotGauge in code or zero-code. Verified versions, install line, and a tested Runner sample.

Records OpenAI Agents SDK runs.

| | |
| - | - |
| Extra | `[openai-agents]` |
| Verified framework versions | openai-agents 0.20.0 and 0.24.0 |
| Instrumentor installed by the extra | `openinference-instrumentation-openai-agents 2.5.3` |
| Zero-code run | Traced |

Also verified: openai-agents 0.20.0 with instrumentor 2.5.0. The extra no longer installs that older instrumentor. See [supported frameworks](https://www.botgauge.com/docs/integrations/overview.md) for how verification works.

## In code

Call `tracing.init()`, attach the framework instrumentor to the provider it returns, and wrap the work in `tracing.turn()` and `tracing.agent()`.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[openai-agents]" openai-agents==0.24.0
```

**2. Add the code**

```python app.py theme={null}
import os

from botgauge import tracing
from agents import Agent, Runner
from openinference.instrumentation.openai_agents import OpenAIAgentsInstrumentor

provider = tracing.init()
OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)

agent = Agent(name="assistant", instructions="Answer briefly.", model=os.environ["OPENAI_MODEL"])

with tracing.turn(session_id="ses_openai_agents"), tracing.agent("openai-agents-agent"):
    result = Runner.run_sync(agent, "In one sentence, what is OpenTelemetry?")
print(result.final_output)

tracing.shutdown()
```

**3. Run**

```bash terminal theme={null}
python app.py
```

Needs `BOTGAUGE_API_KEY`, `OPENAI_API_KEY`, `OPENAI_MODEL`. Set `OPENAI_BASE_URL` too if your LLM isn't api.openai.com.

## Zero-code

Leave your app unchanged and start it with `botgauge instrument`. The sample still wraps the work in `tracing.turn()` and `tracing.agent()` so spans carry session and agent ids.

**1. Install**

```bash terminal theme={null}
pip install "botgauge[openai-agents]" openai-agents==0.24.0
```

**2. Add the code**

```python app.py theme={null}
import os

from botgauge import tracing
from agents import Agent, Runner

agent = Agent(name="assistant", instructions="Answer briefly.", model=os.environ["OPENAI_MODEL"])

with tracing.turn(session_id="ses_openai_agents"), tracing.agent("openai-agents-agent"):
    result = Runner.run_sync(agent, "In one sentence, what is OpenTelemetry?")
print(result.final_output)
```

**3. Run**

```bash terminal theme={null}
botgauge instrument python app.py
```

Needs `BOTGAUGE_API_KEY`, `OPENAI_API_KEY`, `OPENAI_MODEL`. Set `OPENAI_BASE_URL` too if your LLM isn't api.openai.com.

View OpenAI Agents spans liveWatch your OpenAI Agents SDK runs appear in [BotGauge](https://cloud.botgauge.com).

[Try BotGauge →](https://cloud.botgauge.com)

## Related

See [versions not verified](https://www.botgauge.com/docs/integrations/versions-not-verified.md) if you run a different version, [capture and redaction](https://www.botgauge.com/docs/tracing/capture-and-redaction.md) to control exported content, and [troubleshooting](https://www.botgauge.com/docs/tracing/troubleshooting.md) if spans are missing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.