Skip to content

Commit a34668b

Browse files
pass response model directly to update_ai_client_span
1 parent ed1f3ed commit a34668b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

sentry_sdk/integrations/openai_agents/patches/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ async def wrapped_get_response(*args, **kwargs):
5656

5757
response_model = getattr(agent, "_sentry_raw_response_model", None)
5858
if response_model:
59-
result._sentry_response_model = response_model
60-
6159
agent_span = getattr(agent, "_sentry_agent_span", None)
6260
if agent_span:
6361
agent_span.set_data(
@@ -66,7 +64,7 @@ async def wrapped_get_response(*args, **kwargs):
6664

6765
delattr(agent, "_sentry_raw_response_model")
6866

69-
update_ai_client_span(span, agent, kwargs, result)
67+
update_ai_client_span(span, agent, kwargs, result, response_model)
7068

7169
return result
7270

sentry_sdk/integrations/openai_agents/spans/ai_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
if TYPE_CHECKING:
1616
from agents import Agent
17-
from typing import Any
17+
from typing import Any, Optional
1818

1919

2020
def ai_client_span(agent, get_response_kwargs):
@@ -35,12 +35,14 @@ def ai_client_span(agent, get_response_kwargs):
3535
return span
3636

3737

38-
def update_ai_client_span(span, agent, get_response_kwargs, result):
39-
# type: (sentry_sdk.tracing.Span, Agent, dict[str, Any], Any) -> None
38+
def update_ai_client_span(
39+
span, agent, get_response_kwargs, result, response_model=None
40+
):
41+
# type: (sentry_sdk.tracing.Span, Agent, dict[str, Any], Any, Optional[str]) -> None
4042
_set_usage_data(span, result.usage)
4143
_set_output_data(span, result)
4244
_create_mcp_execute_tool_spans(span, result)
4345

4446
# Set response model if captured from raw response
45-
if hasattr(result, "_sentry_response_model") and result._sentry_response_model:
46-
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, result._sentry_response_model)
47+
if response_model is not None:
48+
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response_model)

0 commit comments

Comments
 (0)