@@ -117,6 +117,8 @@ def mock_agent():
117117 frequency_penalty = 0.0 ,
118118 )
119119 agent .tools = []
120+ agent .handoffs = []
121+ agent .output_type = str
120122 return agent
121123
122124
@@ -133,11 +135,14 @@ async def test_agent_invocation_span(
133135 integrations = [OpenAIAgentsIntegration ()],
134136 traces_sample_rate = 1.0 ,
135137 )
138+
136139 events = capture_events ()
137140
138141 with sentry_sdk .start_transaction (name = "test_transaction" ):
139- with patch ("agents.Runner.run" , new_callable = AsyncMock ) as mock_run :
140- mock_run .return_value = mock_run_result
142+ with patch (
143+ "sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
144+ ) as mock_run :
145+ mock_run .return_value = AsyncMock (return_value = mock_run_result )
141146
142147 await agents .Runner .run (mock_agent , "Test input" )
143148
@@ -156,7 +161,7 @@ async def test_agent_invocation_span(
156161
157162@pytest .mark .asyncio
158163async def test_tool_execution_span (
159- sentry_init , capture_events , mock_agent , mock_run_result
164+ sentry_init , capture_events , mock_agent , mock_run_result , mock_tool_call
160165):
161166 sentry_init (
162167 integrations = [OpenAIAgentsIntegration ()],
@@ -166,8 +171,13 @@ async def test_tool_execution_span(
166171 events = capture_events ()
167172
168173 with sentry_sdk .start_transaction (name = "test_transaction" ):
169- with patch ("agents.Runner.run" , new_callable = AsyncMock ) as mock_run :
170- mock_run .return_value = mock_run_result
174+ with patch (
175+ "sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
176+ ) as mock_run , patch (
177+ "sentry_sdk.integrations.openai_agents.patches.tools._create_get_all_tools_wrapper"
178+ ) as mock_tools :
179+ mock_run .return_value = AsyncMock (return_value = mock_run_result )
180+ mock_tools .return_value = AsyncMock (return_value = [mock_tool_call ])
171181
172182 await agents .Runner .run (mock_agent , "Test input" )
173183
@@ -194,8 +204,13 @@ async def test_llm_request_span(
194204 events = capture_events ()
195205
196206 with sentry_sdk .start_transaction (name = "test_transaction" ):
197- with patch ("agents.Runner.run" , new_callable = AsyncMock ) as mock_run :
198- mock_run .return_value = mock_run_result
207+ with patch (
208+ "sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
209+ ) as mock_run , patch (
210+ "sentry_sdk.integrations.openai_agents.patches.models._create_get_model_wrapper"
211+ ) as mock_model :
212+ mock_run .return_value = AsyncMock (return_value = mock_run_result )
213+ mock_model .return_value = AsyncMock (return_value = mock_model_response )
199214
200215 await agents .Runner .run (mock_agent , "Test input" )
201216
@@ -221,8 +236,10 @@ async def test_error_handling(sentry_init, capture_events, mock_agent):
221236 events = capture_events ()
222237
223238 with sentry_sdk .start_transaction (name = "test_transaction" ) as transaction :
224- with patch ("agents.Runner.run" , new_callable = AsyncMock ) as mock_run :
225- mock_run .side_effect = AgentsException ("Test error" )
239+ with patch (
240+ "sentry_sdk.integrations.openai_agents.patches.runner._create_run_wrapper"
241+ ) as mock_run :
242+ mock_run .return_value = AsyncMock (side_effect = AgentsException ("Test error" ))
226243
227244 with pytest .raises (AgentsException ):
228245 await agents .Runner .run (mock_agent , "Test input" )
0 commit comments