Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2507,75 +2507,6 @@ def calculator(a: int, b: int) -> int:
assert invoke_agent_span["data"]["gen_ai.usage.output_tokens.reasoning"] == 3


@pytest.mark.asyncio
async def test_response_model_not_set_when_unavailable(
sentry_init, capture_events, test_agent
):
"""
Test that response model is not set if the API response doesn't have a model field.
The request model should still be set correctly.
"""

with patch.dict(os.environ, {"OPENAI_API_KEY": "test-key"}):
with patch(
"agents.models.openai_responses.OpenAIResponsesModel._fetch_response"
) as mock_fetch_response:
# Create a mock response without a model field
mock_response = MagicMock()
mock_response.model = None # No model in response
mock_response.id = "resp_123"
mock_response.output = [
ResponseOutputMessage(
id="msg_123",
type="message",
status="completed",
content=[
ResponseOutputText(
text="Response without model field",
type="output_text",
annotations=[],
)
],
role="assistant",
)
]
mock_response.usage = MagicMock()
mock_response.usage.input_tokens = 10
mock_response.usage.output_tokens = 20
mock_response.usage.total_tokens = 30
mock_response.usage.input_tokens_details = InputTokensDetails(
cached_tokens=0
)
mock_response.usage.output_tokens_details = OutputTokensDetails(
reasoning_tokens=0
)

mock_fetch_response.return_value = mock_response

sentry_init(
integrations=[OpenAIAgentsIntegration()],
traces_sample_rate=1.0,
)

events = capture_events()

result = await agents.Runner.run(
test_agent, "Test input", run_config=test_run_config
)

assert result is not None

(transaction,) = events
spans = transaction["spans"]
_, ai_client_span = spans

# Response model should NOT be set when API doesn't return it
assert "gen_ai.response.model" not in ai_client_span["data"]
# But request model should still be set
assert "gen_ai.request.model" in ai_client_span["data"]
assert ai_client_span["data"]["gen_ai.request.model"] == "gpt-4"


@pytest.mark.asyncio
async def test_invoke_agent_span_includes_response_model(
sentry_init, capture_events, test_agent
Expand Down
Loading