Skip to content

Commit 49dbc3a

Browse files
Merge branch 'master' into webb/openai-agents/non-error-single-response
2 parents 0d13b60 + cdeec8c commit 49dbc3a

File tree

2 files changed

+0
-71
lines changed

2 files changed

+0
-71
lines changed

sentry_sdk/integrations/openai_agents/patches/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ async def wrapped_get_response(*args: "Any", **kwargs: "Any") -> "Any":
133133

134134
@wraps(original_stream_response)
135135
async def wrapped_stream_response(*args: "Any", **kwargs: "Any") -> "Any":
136-
# Uses explicit try/finally instead of context manager to ensure cleanup
137-
# even if the consumer abandons the stream (GeneratorExit).
138136
span_kwargs = dict(kwargs)
139137
if len(args) > 0:
140138
span_kwargs["system_instructions"] = args[0]

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,75 +2629,6 @@ def calculator(a: int, b: int) -> int:
26292629
assert invoke_agent_span["data"]["gen_ai.usage.output_tokens.reasoning"] == 3
26302630

26312631

2632-
@pytest.mark.asyncio
2633-
async def test_response_model_not_set_when_unavailable(
2634-
sentry_init, capture_events, test_agent
2635-
):
2636-
"""
2637-
Test that response model is not set if the API response doesn't have a model field.
2638-
The request model should still be set correctly.
2639-
"""
2640-
2641-
with patch.dict(os.environ, {"OPENAI_API_KEY": "test-key"}):
2642-
with patch(
2643-
"agents.models.openai_responses.OpenAIResponsesModel._fetch_response"
2644-
) as mock_fetch_response:
2645-
# Create a mock response without a model field
2646-
mock_response = MagicMock()
2647-
mock_response.model = None # No model in response
2648-
mock_response.id = "resp_123"
2649-
mock_response.output = [
2650-
ResponseOutputMessage(
2651-
id="msg_123",
2652-
type="message",
2653-
status="completed",
2654-
content=[
2655-
ResponseOutputText(
2656-
text="Response without model field",
2657-
type="output_text",
2658-
annotations=[],
2659-
)
2660-
],
2661-
role="assistant",
2662-
)
2663-
]
2664-
mock_response.usage = MagicMock()
2665-
mock_response.usage.input_tokens = 10
2666-
mock_response.usage.output_tokens = 20
2667-
mock_response.usage.total_tokens = 30
2668-
mock_response.usage.input_tokens_details = InputTokensDetails(
2669-
cached_tokens=0
2670-
)
2671-
mock_response.usage.output_tokens_details = OutputTokensDetails(
2672-
reasoning_tokens=0
2673-
)
2674-
2675-
mock_fetch_response.return_value = mock_response
2676-
2677-
sentry_init(
2678-
integrations=[OpenAIAgentsIntegration()],
2679-
traces_sample_rate=1.0,
2680-
)
2681-
2682-
events = capture_events()
2683-
2684-
result = await agents.Runner.run(
2685-
test_agent, "Test input", run_config=test_run_config
2686-
)
2687-
2688-
assert result is not None
2689-
2690-
(transaction,) = events
2691-
spans = transaction["spans"]
2692-
_, ai_client_span = spans
2693-
2694-
# Response model should NOT be set when API doesn't return it
2695-
assert "gen_ai.response.model" not in ai_client_span["data"]
2696-
# But request model should still be set
2697-
assert "gen_ai.request.model" in ai_client_span["data"]
2698-
assert ai_client_span["data"]["gen_ai.request.model"] == "gpt-4"
2699-
2700-
27012632
@pytest.mark.asyncio
27022633
async def test_invoke_agent_span_includes_response_model(
27032634
sentry_init,

0 commit comments

Comments
 (0)