2121
2222try :
2323 import agents
24- from agents .exceptions import AgentsException
2524except ImportError :
2625 raise DidNotEnable ("OpenAI Agents not installed" )
2726
@@ -48,15 +47,6 @@ def _start_invoke_agent_span(context_wrapper, agent, kwargs):
4847
4948 return span
5049
51- def _end_invoke_agent_span (context_wrapper , agent , output = None ):
52- # type: (agents.RunContextWrapper, agents.Agent, Optional[Any]) -> None
53- """End the agent invocation span"""
54- # Clear the stored agent
55- if hasattr (context_wrapper , "_sentry_current_agent" ):
56- delattr (context_wrapper , "_sentry_current_agent" )
57-
58- update_invoke_agent_span (context_wrapper , agent , output )
59-
6050 def _has_active_agent_span (context_wrapper ):
6151 # type: (agents.RunContextWrapper) -> bool
6252 """Check if there's an active agent span for this context"""
@@ -129,7 +119,7 @@ async def patched_execute_handoffs(cls, *args, **kwargs):
129119 finally :
130120 # End span for current agent after handoff processing is complete
131121 if agent and context_wrapper and _has_active_agent_span (context_wrapper ):
132- _end_invoke_agent_span (context_wrapper , agent )
122+ end_invoke_agent_span (context_wrapper , agent )
133123
134124 return result
135125
@@ -152,7 +142,7 @@ async def patched_execute_final_output(cls, *args, **kwargs):
152142 finally :
153143 # End span for current agent after final output processing is complete
154144 if agent and context_wrapper and _has_active_agent_span (context_wrapper ):
155- _end_invoke_agent_span (context_wrapper , agent , final_output )
145+ end_invoke_agent_span (context_wrapper , agent , final_output )
156146
157147 return result
158148
0 commit comments