Skip to content

Commit ffadd7d

Browse files
Python docs for the openai-agents integration (#14113)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Documentation on how to use the AI Agents integration for the `openai-agents` package. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [x] Urgent deadline (GA date, etc.): GA date: 2025-6-26 - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [x] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
1 parent 815ecd4 commit ffadd7d

File tree

2 files changed

+122
-6
lines changed

2 files changed

+122
-6
lines changed

docs/platforms/python/integrations/index.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
3838

3939
### AI
4040

41-
| | **Auto-enabled** |
42-
| ------------------------------------------------------------------------------------------------------------------------------------ | :--------------: |
43-
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> ||
44-
| <LinkWithPlatformIcon platform="huggingface" label="Huggingface Hub" url="/platforms/python/integrations/huggingface_hub" /> ||
45-
| <LinkWithPlatformIcon platform="langchain" label="Langchain" url="/platforms/python/integrations/langchain" /> ||
46-
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> ||
41+
| | **Auto-enabled** |
42+
| -------------------------------------------------------------------------------------------------------------------------------------- | :--------------: |
43+
| <LinkWithPlatformIcon platform="anthropic" label="Anthropic" url="/platforms/python/integrations/anthropic" /> ||
44+
| <LinkWithPlatformIcon platform="huggingface" label="Huggingface Hub" url="/platforms/python/integrations/huggingface_hub" /> ||
45+
| <LinkWithPlatformIcon platform="langchain" label="Langchain" url="/platforms/python/integrations/langchain" /> ||
46+
| <LinkWithPlatformIcon platform="openai" label="OpenAI" url="/platforms/python/integrations/openai" /> ||
47+
| <LinkWithPlatformIcon platform="openai-agents" label="OpenAI Agents SDK" url="/platforms/python/integrations/openai-agents" /> | |
4748

4849
### Data Processing
4950

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: OpenAI Agents
3+
description: "Learn about using Sentry for OpenAI Agents SDK."
4+
---
5+
6+
<Alert title="Beta">
7+
8+
The support for **OpenAI Agents SDK** is in its beta phase. Please test locally before using in production.
9+
10+
</Alert>
11+
12+
This integration connects Sentry with the [OpenAI Python SDK](https://openai.github.io/openai-agents-python/).
13+
The integration has been confirmed to work with OpenAI Agents version 0.0.19.
14+
15+
Once you've installed this SDK, you can use [Sentry AI Agents Insights](https://sentry.io/orgredirect/organizations/:orgslug/insights/agents/), a Sentry dashboard that helps you understand what's going on with your AI agents.
16+
17+
Sentry AI Agents monitoring will automatically collect information about agents, tools, prompts, tokens, and models.
18+
19+
## Install
20+
21+
Install `sentry-sdk` from PyPI:
22+
23+
```bash {tabTitle:pip}
24+
pip install "sentry-sdk"
25+
```
26+
27+
```bash {tabTitle:uv}
28+
uv add "sentry-sdk"
29+
```
30+
31+
## Configure
32+
33+
Add `OpenAIAgentsIntegration()` to your `integrations` list:
34+
35+
```python
36+
import sentry_sdk
37+
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration
38+
39+
sentry_sdk.init(
40+
dsn="___PUBLIC_DSN___",
41+
# Add data like inputs and responses to/from LLMs and tools;
42+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
43+
send_default_pii=True,
44+
integrations=[
45+
OpenAIAgentsIntegration(),
46+
],
47+
)
48+
```
49+
50+
## Verify
51+
52+
Verify that the integration works by running an AI agent. The resulting data should show up in your AI Agents Insights dashboard.
53+
54+
```python
55+
import asyncio
56+
import random
57+
58+
import sentry_sdk
59+
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration
60+
61+
import agents
62+
from pydantic import BaseModel # installed by openai-agents
63+
64+
@agents.function_tool
65+
def random_number(max: int) -> int:
66+
return random.randint(0, max)
67+
68+
class FinalResult(BaseModel):
69+
number: int
70+
71+
random_number_agent = agents.Agent(
72+
name="Random Number Agent",
73+
instructions="Generate a random number.",
74+
tools=[random_number, ],
75+
output_type=FinalResult,
76+
model="gpt-4o-mini",
77+
)
78+
79+
async def main() -> None:
80+
sentry_sdk.init(
81+
dsn="...", # same as above
82+
# Add data like LLM and tool inputs/outputs;
83+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
84+
send_default_pii=True,
85+
integrations=[
86+
OpenAIAgentsIntegration(),
87+
],
88+
)
89+
90+
await agents.Runner.run(
91+
random_number_agent,
92+
input=f"Generate a random number between 0 and {10}.",
93+
)
94+
95+
if __name__ == "__main__":
96+
asyncio.run(main())
97+
```
98+
99+
It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io).
100+
101+
## Behavior
102+
103+
Data on the following will be collected:
104+
105+
- AI agents invocations
106+
- execution of tools
107+
- number of input and output tokens used
108+
- LLM models usage
109+
110+
Sentry considers LLM and tool inputs/outputs as PII and doesn't include PII data by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call.
111+
112+
## Supported Versions
113+
114+
- OpenAI Agents SDK: 0.0.19+
115+
- Python: 3.9+

0 commit comments

Comments
 (0)