Skip to content

Commit d1f6f8d

Browse files
fix(pydantic-ai): Determine if response is streamed based on the method
1 parent 6ef56fd commit d1f6f8d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from functools import wraps
33

44
from sentry_sdk.integrations import DidNotEnable
5+
from sentry_sdk.consts import SPANDATA
56

67
from ..spans import (
78
ai_client_span,
@@ -60,6 +61,8 @@ async def wrapped_model_request_run(self: "Any", ctx: "Any") -> "Any":
6061
messages, model, model_settings = _extract_span_data(self, ctx)
6162

6263
with ai_client_span(messages, None, model, model_settings) as span:
64+
span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, True)
65+
6366
result = await original_model_request_run(self, ctx)
6467

6568
# Extract response from result if available
@@ -87,6 +90,8 @@ async def wrapped_model_request_stream(self: "Any", ctx: "Any") -> "Any":
8790

8891
# Create chat span for streaming request
8992
with ai_client_span(messages, None, model, model_settings) as span:
93+
span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, False)
94+
9095
# Call the original stream method
9196
async with original_stream_method(self, ctx) as stream:
9297
yield stream

sentry_sdk/integrations/pydantic_ai/spans/ai_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
_should_send_prompts,
1818
_get_model_name,
1919
get_current_agent,
20-
get_is_streaming,
2120
)
2221
from .utils import (
2322
_serialize_binary_content_item,
@@ -264,9 +263,6 @@ def ai_client_span(
264263
_set_agent_data(span, agent)
265264
_set_model_data(span, model, model_settings)
266265

267-
# Set streaming flag from contextvar
268-
span.set_data(SPANDATA.GEN_AI_RESPONSE_STREAMING, get_is_streaming())
269-
270266
# Add available tools if agent is available
271267
agent_obj = agent or get_current_agent()
272268
_set_available_tools(span, agent_obj)

0 commit comments

Comments
 (0)