Skip to content

Commit 0f0dc8b

Browse files
fix(pydantic-ai): Stop truncating in the streaming trace lifecycle
1 parent e7262e9 commit 0f0dc8b

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

sentry_sdk/integrations/pydantic_ai/spans/ai_client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
)
1010
from sentry_sdk.consts import OP, SPANDATA
1111
from sentry_sdk.traces import StreamedSpan
12-
from sentry_sdk.tracing_utils import has_span_streaming_enabled
12+
from sentry_sdk.tracing_utils import (
13+
has_span_streaming_enabled,
14+
should_truncate_gen_ai_input,
15+
)
1316
from sentry_sdk.utils import safe_serialize
1417

1518
from ..consts import SPAN_ORIGIN
@@ -200,9 +203,9 @@ def _set_input_messages(
200203
client = sentry_sdk.get_client()
201204
scope = sentry_sdk.get_current_scope()
202205
messages_data = (
203-
normalized_messages
204-
if client.options.get("stream_gen_ai_spans", False)
205-
else truncate_and_annotate_messages(normalized_messages, span, scope)
206+
truncate_and_annotate_messages(normalized_messages, span, scope)
207+
if should_truncate_gen_ai_input(client.options)
208+
else normalized_messages
206209
)
207210
set_data_normalized(
208211
span, SPANDATA.GEN_AI_REQUEST_MESSAGES, messages_data, unpack=False

sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
)
1010
from sentry_sdk.consts import OP, SPANDATA
1111
from sentry_sdk.traces import StreamedSpan
12-
from sentry_sdk.tracing_utils import has_span_streaming_enabled
12+
from sentry_sdk.tracing_utils import (
13+
has_span_streaming_enabled,
14+
should_truncate_gen_ai_input,
15+
)
1316

1417
from ..consts import SPAN_ORIGIN
1518
from ..utils import (
@@ -137,9 +140,9 @@ def invoke_agent_span(
137140
client = sentry_sdk.get_client()
138141
scope = sentry_sdk.get_current_scope()
139142
messages_data = (
140-
normalized_messages
141-
if client.options.get("stream_gen_ai_spans", False)
142-
else truncate_and_annotate_messages(normalized_messages, span, scope)
143+
truncate_and_annotate_messages(normalized_messages, span, scope)
144+
if should_truncate_gen_ai_input(client.options)
145+
else normalized_messages
143146
)
144147
set_data_normalized(
145148
span, SPANDATA.GEN_AI_REQUEST_MESSAGES, messages_data, unpack=False

0 commit comments

Comments
 (0)