Skip to content

Support openai-agents #4437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 95 commits into from
Jun 24, 2025
Merged

Conversation

antonpirker
Copy link
Member

@antonpirker antonpirker commented Jun 3, 2025

Add support for AI agents projects using openai-agents (https://pypi.org/project/openai-agents/)

Docs PR is here: getsentry/sentry-docs#14113

This integration:

  • records tracing data of agent invocation, tool execution, ai client requests to LLMs, and handoffs to other agents.
  • captures input and output to/from LLMs if set_default_pii=True.
  • is mostly compatible to the OpenTelememetry gen_ai semantic conventions. (input and output is not compatible because Sentry does not have Span events. This information is stored in arrays on the Span attributes.
  • Captures errors that happen during agent execution (like problems during interaction with the LLM.

This integration does not:

  • Capture errors during function tool exection because this is very hard to patch (see comment in the code)

Example span tree in Sentry.io:
Screenshot 2025-06-24 at 12 15 17

Copy link

codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 77 lines in your changes missing coverage. Please review.

Project coverage is 80.64%. Comparing base (ad2bbff) to head (4e4f39c).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/openai_agents/utils.py 72.56% 23 Missing and 8 partials ⚠️
...dk/integrations/openai_agents/patches/agent_run.py 80.00% 8 Missing and 5 partials ⚠️
...ry_sdk/integrations/openai_agents/patches/tools.py 78.12% 6 Missing and 1 partial ⚠️
...k/integrations/openai_agents/spans/execute_tool.py 75.00% 3 Missing and 3 partials ⚠️
...y_sdk/integrations/openai_agents/patches/models.py 83.33% 4 Missing ⚠️
...k/integrations/openai_agents/spans/invoke_agent.py 77.77% 3 Missing and 1 partial ⚠️
...y_sdk/integrations/openai_agents/patches/runner.py 86.95% 2 Missing and 1 partial ⚠️
..._sdk/integrations/openai_agents/spans/ai_client.py 82.35% 3 Missing ⚠️
sentry_sdk/integrations/openai_agents/__init__.py 90.00% 2 Missing ⚠️
...integrations/openai_agents/spans/agent_workflow.py 77.77% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4437      +/-   ##
==========================================
+ Coverage   80.57%   80.64%   +0.06%     
==========================================
  Files         142      156      +14     
  Lines       16057    16475     +418     
  Branches     2748     2805      +57     
==========================================
+ Hits        12938    13286     +348     
- Misses       2251     2304      +53     
- Partials      868      885      +17     
Files with missing lines Coverage Δ
sentry_sdk/consts.py 94.63% <100.00%> (+1.18%) ⬆️
sentry_sdk/integrations/__init__.py 77.01% <ø> (ø)
sentry_sdk/integrations/openai_agents/consts.py 100.00% <100.00%> (ø)
...sdk/integrations/openai_agents/patches/__init__.py 100.00% <100.00%> (ø)
...y_sdk/integrations/openai_agents/spans/__init__.py 100.00% <100.00%> (ø)
sentry_sdk/integrations/openai_agents/__init__.py 90.00% <90.00%> (ø)
...integrations/openai_agents/spans/agent_workflow.py 77.77% <77.77%> (ø)
...ry_sdk/integrations/openai_agents/spans/handoff.py 77.77% <77.77%> (ø)
...y_sdk/integrations/openai_agents/patches/runner.py 86.95% <86.95%> (ø)
..._sdk/integrations/openai_agents/spans/ai_client.py 82.35% <82.35%> (ø)
... and 6 more

... and 2 files with indirect coverage changes

@antonpirker antonpirker marked this pull request as ready for review June 23, 2025 12:00
@antonpirker antonpirker requested a review from a team as a code owner June 23, 2025 12:00
@antonpirker antonpirker requested a review from sentrivana June 24, 2025 10:16
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

But let the record show I don't like having the spans stuff in separate files 😢

@antonpirker antonpirker enabled auto-merge (squash) June 24, 2025 12:24
@antonpirker
Copy link
Member Author

Thanks Ivana!

@antonpirker antonpirker merged commit 4a0e5ed into master Jun 24, 2025
136 checks passed
@antonpirker antonpirker deleted the antonpirker/openai-agents-integration branch June 24, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants