Skip to content

Commit 1a1ab90

Browse files
add one missing test
1 parent 2378fd9 commit 1a1ab90

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,9 @@ async def test_hosted_mcp_tool_propagation_header_streamed(sentry_init, test_age
14921492

14931493

14941494
@pytest.mark.asyncio
1495-
async def test_hosted_mcp_tool_propagation_headers(sentry_init, test_agent):
1495+
async def test_hosted_mcp_tool_propagation_headers(
1496+
sentry_init, test_agent, get_model_response
1497+
):
14961498
"""
14971499
Test responses API is given trace propagation headers with HostedMCPTool.
14981500
"""
@@ -1508,9 +1510,7 @@ async def test_hosted_mcp_tool_propagation_headers(sentry_init, test_agent):
15081510
},
15091511
)
15101512

1511-
client = AsyncOpenAI(api_key="z")
1512-
client.responses._post = AsyncMock(return_value=EXAMPLE_RESPONSE)
1513-
1513+
client = AsyncOpenAI(api_key="test-key")
15141514
model = OpenAIResponsesModel(model="gpt-4", openai_client=client)
15151515

15161516
agent_with_tool = test_agent.clone(
@@ -1524,11 +1524,13 @@ async def test_hosted_mcp_tool_propagation_headers(sentry_init, test_agent):
15241524
release="d08ebdb9309e1b004c6f52202de58a09c2268e42",
15251525
)
15261526

1527+
response = get_model_response(EXAMPLE_RESPONSE)
1528+
15271529
with patch.object(
1528-
model._client.responses,
1529-
"create",
1530-
wraps=model._client.responses.create,
1531-
) as create, mock.patch(
1530+
agent_with_tool.model._client._client,
1531+
"send",
1532+
return_value=response,
1533+
) as send, mock.patch(
15321534
"sentry_sdk.tracing_utils.Random.randrange", return_value=500000
15331535
):
15341536
with sentry_sdk.start_transaction(
@@ -1542,13 +1544,17 @@ async def test_hosted_mcp_tool_propagation_headers(sentry_init, test_agent):
15421544
run_config=test_run_config,
15431545
)
15441546

1545-
ai_client_span = transaction._span_recorder.spans[-1]
1547+
ai_client_span = next(
1548+
span
1549+
for span in transaction._span_recorder.spans
1550+
if span.op == OP.GEN_AI_CHAT
1551+
)
15461552

1547-
args, kwargs = create.call_args
1553+
args, kwargs = send.call_args
15481554

1549-
assert "tools" in kwargs
1550-
assert len(kwargs["tools"]) == 1
1551-
hosted_mcp_tool = kwargs["tools"][0]
1555+
request = args[0]
1556+
body = json.loads(request.content.decode("utf-8"))
1557+
hosted_mcp_tool = body["tools"][0]
15521558

15531559
assert hosted_mcp_tool["headers"][
15541560
"sentry-trace"

0 commit comments

Comments
 (0)