Skip to content

Commit 1493e35

Browse files
mypy
1 parent 61bf6a8 commit 1493e35

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
truncate_and_annotate_messages,
99
)
1010
from sentry_sdk.consts import OP, SPANDATA
11+
from sentry_sdk.traces import StreamedSpan
1112
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1213

1314
from ..consts import SPAN_ORIGIN
@@ -38,7 +39,7 @@ def invoke_agent_span(
3839
model: "Any",
3940
model_settings: "Any",
4041
is_streaming: bool = False,
41-
) -> "Union[sentry_sdk.tracing.Span, sentry_sdk.traces.StreamedSpan]":
42+
) -> "Union[sentry_sdk.tracing.Span, StreamedSpan]":
4243
"""Create a span for invoking the agent."""
4344
# Determine agent name for span
4445
name = "agent"
@@ -148,7 +149,7 @@ def invoke_agent_span(
148149

149150

150151
def update_invoke_agent_span(
151-
span: "Union[sentry_sdk.tracing.Span, sentry_sdk.traces.StreamedSpan]",
152+
span: "Union[sentry_sdk.tracing.Span, StreamedSpan]",
152153
result: "Any",
153154
) -> None:
154155
"""Update and close the invoke agent span."""
@@ -169,7 +170,12 @@ def update_invoke_agent_span(
169170
try:
170171
response = result.response
171172
if hasattr(response, "model_name") and response.model_name:
172-
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response.model_name)
173+
if isinstance(span, StreamedSpan):
174+
span.set_attribute(
175+
SPANDATA.GEN_AI_RESPONSE_MODEL, response.model_name
176+
)
177+
else:
178+
span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response.model_name)
173179
except Exception:
174180
# If response access fails, continue without setting model name
175181
pass

0 commit comments

Comments
 (0)