Skip to content

Commit cb41f97

Browse files
delay messages in stream path
1 parent 1f1cc44 commit cb41f97

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ async def wrapped_model_request_stream(self: "Any", ctx: "Any") -> "Any":
9494

9595
# Create chat span for streaming request
9696
with ai_client_span(None, model, model_settings) as span:
97-
if messages:
98-
_set_input_messages(span, messages)
99-
10097
# Call the original stream method
10198
async with original_stream_method(self, ctx) as stream:
99+
# The instructions are added in `_prepare_request` that runs as part of __aenter__ on the
100+
# context manager returned by `ModelRequestNode.stream()`, so the input must be recorded after the
101+
# call. See _get_instructions() added with
102+
# https://github.com/pydantic/pydantic-ai/commit/f5271434a56c7a3bb5a3c93f2d1236d8b18afe3e
103+
if messages:
104+
_set_input_messages(span, messages)
105+
102106
yield stream
103107

104108
# After streaming completes, update span with response data

0 commit comments

Comments
 (0)