You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'Span' object has no attribute '_context_manager_state' #4718
{
"error": "'Span' object has no attribute '_context_manager_state'",
"tool_name": "<agentname>_agent"
}
Expected Result
This error not to happen
That most (if not all) parts of the Sentry SDK are wrapped in try catch blocks, so that if for some reason like now a Span cannot be closed, it doesn't interfere with the normal flow
Actual Result
The agent crashes, and instead of the result that was generated by the nested agent being available to the main agent, the main agent only sees the error message and cannot continue.
This does look similar to what I wanted to patch with #4698, but it's not the same since in your case, it's the Span complaining about the missing attribute, and in the PR it was the profiler.
All in all though it looks like there's a more fundamental issue with tracing (and profiling, by extension) in the OpenAIAgentsIntegration. But at the very least we should, of course, not error out like this. I'll see if I can find the issue; otherwise I'll at least patch our code so that we don't throw an exception.
An example to reproduce (even if not consistently) would be super helpful -- in my tests I haven't been able to trigger this so far.
Hey @Afstkla, of course, it goes without saying that the SDK should never break a user's app. That being said, the OpenAI agents integration is still in beta so there might be (and apparently are) things that need ironing out. We're on them with high prio -- also thanks to you raising them and following up. 🙏🏻
Re: release, v2.36.0 of the SDK is out. It includes the fix #4736 I mentioned above as well as some error silencing around span/profiler restoration (#4698, #4719). Do you happen to have a non-prod environment where you could give this a spin?
Thx for the response! We'll test it out (tho not in prod) but as it seems mostly a multithreading issue, it might be quite difficult to reproduce in an env where we have not the traffic of prod.. Will keep you posted when we test & encounter anything
Activity
linear commentedon Aug 25, 2025
PY-1815 'Span' object has no attribute '_context_manager_state'
Afstkla commentedon Aug 25, 2025
(probably duplicate of #4698, sorry, just found that one)
sentrivana commentedon Aug 25, 2025
Hey @Afstkla, thanks for reporting.
This does look similar to what I wanted to patch with #4698, but it's not the same since in your case, it's the
Spancomplaining about the missing attribute, and in the PR it was the profiler.All in all though it looks like there's a more fundamental issue with tracing (and profiling, by extension) in the
OpenAIAgentsIntegration. But at the very least we should, of course, not error out like this. I'll see if I can find the issue; otherwise I'll at least patch our code so that we don't throw an exception.An example to reproduce (even if not consistently) would be super helpful -- in my tests I haven't been able to trigger this so far.
35 remaining items
Afstkla commentedon Sep 4, 2025
Thx for the response! We'll test it out (tho not in prod) but as it seems mostly a multithreading issue, it might be quite difficult to reproduce in an env where we have not the traffic of prod.. Will keep you posted when we test & encounter anything
Afstkla commentedon Sep 10, 2025
@sentrivana haven't seen any occurrences of this happening anymore, so deployed to prod and so far so good. Thanks for the support!
antonpirker commentedon Sep 11, 2025
This issue was fixed by the patch mentioned above. I will close this issue.