Skip to content

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Nov 27, 2025

Description

Using sentry_sdk.get_current_span() is problematic with the asyncio integration. The integration forks the isolation and current scopes, so sentry_sdk.get_current_span() can return a span that does not correspond to the agent invocation.

The coroutine in which the agent span is entered finishes before the agent span is finished. When the coroutine exits, its scopes are popped, and the agent invocation span is lost before it is exited. You can confirm by setting breakpoints in the asyncio and openai-agents integrations, and running the reproduction provided in #5067.

See more details here #5067 (comment).

Issues

Closes #5067

Reminders

@alexander-alderman-webb alexander-alderman-webb changed the title fix(openai-agents): Store invoke_agent span on agents.RunContextWrapper fix(openai-agents): Store invoke_agent span on agents.RunContextWrapper Nov 27, 2025
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review November 27, 2025 12:29
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner November 27, 2025 12:29
@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.91%. Comparing base (de0263f) to head (bc982ed).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5165      +/-   ##
==========================================
- Coverage   83.96%   83.91%   -0.06%     
==========================================
  Files         181      181              
  Lines       18340    18342       +2     
  Branches     3260     3260              
==========================================
- Hits        15400    15392       -8     
- Misses       1936     1944       +8     
- Partials     1004     1006       +2     
Files with missing lines Coverage Δ
...dk/integrations/openai_agents/patches/agent_run.py 82.81% <100.00%> (+0.27%) ⬆️
...k/integrations/openai_agents/spans/invoke_agent.py 88.23% <100.00%> (+0.35%) ⬆️

... and 3 files with indirect coverage changes

@alexander-alderman-webb alexander-alderman-webb merged commit 996f935 into master Dec 1, 2025
155 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/store-span-on-openai-agents-context-wrapper branch December 1, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: in OpenAIAgentsIntegration + AsyncioIntegration: '_context_manager_state' not found

3 participants