Skip to content

Commit bd17033

Browse files
authored
Merge branch 'master' into toxgen/update-06-29
2 parents bfee9fd + 9c83606 commit bd17033

16 files changed

Lines changed: 91 additions & 132 deletions

File tree

scripts/populate_tox/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
"deps": {
304304
"*": ["pytest-asyncio"],
305305
},
306+
"include": "<2.0.0", # Alphas are currently being released, will come back to these before the release that's expected at the end of July 2026
306307
},
307308
"fastmcp": {
308309
"package": "fastmcp",

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def __init__(
13341334
before_send_metric: "Optional[Callable[[Metric, Hint], Optional[Metric]]]" = None,
13351335
org_id: "Optional[str]" = None,
13361336
strict_trace_continuation: bool = False,
1337-
stream_gen_ai_spans: bool = False,
1337+
stream_gen_ai_spans: bool = True,
13381338
) -> None:
13391339
"""Initialize the Sentry SDK with the given parameters. All parameters described here can be used in a call to `sentry_sdk.init()`.
13401340

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

sentry_sdk/traces.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def __init__(
275275
self._active: bool = active
276276
self._attributes: "Attributes" = {
277277
"sentry.origin": "manual",
278+
"sentry.trace_lifecycle": "stream",
278279
}
279280

280281
if attributes:

sentry_sdk/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def finish(
10421042

10431043
finished_spans = []
10441044
has_gen_ai_span = False
1045-
if client.options.get("stream_gen_ai_spans", False):
1045+
if client.options.get("stream_gen_ai_spans", True):
10461046
for span in self._span_recorder.spans:
10471047
if span.timestamp is None:
10481048
continue

sentry_sdk/tracing_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def should_truncate_gen_ai_input(options: "Optional[dict[str, Any]]") -> bool:
121121
return True
122122

123123
return not options.get(
124-
"stream_gen_ai_spans", False
124+
"stream_gen_ai_spans", True
125125
) and not has_span_streaming_enabled(options)
126126

127127

tests/integrations/anthropic/test_anthropic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,6 +3817,7 @@ def test_anthropic_message_truncation(sentry_init, capture_events):
38173817
integrations=[AnthropicIntegration(include_prompts=True)],
38183818
traces_sample_rate=1.0,
38193819
send_default_pii=True,
3820+
stream_gen_ai_spans=False,
38203821
)
38213822
events = capture_events()
38223823

@@ -3869,6 +3870,7 @@ async def test_anthropic_message_truncation_async(sentry_init, capture_events):
38693870
integrations=[AnthropicIntegration(include_prompts=True)],
38703871
traces_sample_rate=1.0,
38713872
send_default_pii=True,
3873+
stream_gen_ai_spans=False,
38723874
)
38733875
events = capture_events()
38743876

@@ -5337,6 +5339,7 @@ def test_message_with_base64_image(sentry_init, capture_events):
53375339
integrations=[AnthropicIntegration(include_prompts=True)],
53385340
traces_sample_rate=1.0,
53395341
send_default_pii=True,
5342+
stream_gen_ai_spans=False,
53405343
)
53415344
events = capture_events()
53425345
client = Anthropic(api_key="z")
@@ -5531,6 +5534,7 @@ def test_message_with_base64_pdf(sentry_init, capture_events):
55315534
integrations=[AnthropicIntegration(include_prompts=True)],
55325535
traces_sample_rate=1.0,
55335536
send_default_pii=True,
5537+
stream_gen_ai_spans=False,
55345538
)
55355539
events = capture_events()
55365540
client = Anthropic(api_key="z")
@@ -5719,6 +5723,7 @@ def test_message_with_mixed_content(sentry_init, capture_events):
57195723
integrations=[AnthropicIntegration(include_prompts=True)],
57205724
traces_sample_rate=1.0,
57215725
send_default_pii=True,
5726+
stream_gen_ai_spans=False,
57225727
)
57235728
events = capture_events()
57245729
client = Anthropic(api_key="z")
@@ -5802,6 +5807,7 @@ def test_message_with_multiple_images_different_formats(sentry_init, capture_eve
58025807
integrations=[AnthropicIntegration(include_prompts=True)],
58035808
traces_sample_rate=1.0,
58045809
send_default_pii=True,
5810+
stream_gen_ai_spans=False,
58055811
)
58065812
events = capture_events()
58075813
client = Anthropic(api_key="z")

tests/integrations/google_genai/test_google_genai.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,7 @@ def test_google_genai_message_truncation(
15031503
integrations=[GoogleGenAIIntegration(include_prompts=True)],
15041504
traces_sample_rate=1.0,
15051505
send_default_pii=True,
1506+
stream_gen_ai_spans=False,
15061507
)
15071508
events = capture_events()
15081509

@@ -2672,6 +2673,7 @@ def test_generate_content_with_function_response(
26722673
integrations=[GoogleGenAIIntegration(include_prompts=True)],
26732674
traces_sample_rate=1.0,
26742675
send_default_pii=True,
2676+
stream_gen_ai_spans=False,
26752677
)
26762678
events = capture_events()
26772679

@@ -2727,6 +2729,7 @@ def test_generate_content_with_mixed_string_and_content(
27272729
integrations=[GoogleGenAIIntegration(include_prompts=True)],
27282730
traces_sample_rate=1.0,
27292731
send_default_pii=True,
2732+
stream_gen_ai_spans=False,
27302733
)
27312734
events = capture_events()
27322735

@@ -2837,6 +2840,7 @@ def test_generate_content_with_list_of_dicts(
28372840
integrations=[GoogleGenAIIntegration(include_prompts=True)],
28382841
traces_sample_rate=1.0,
28392842
send_default_pii=True,
2843+
stream_gen_ai_spans=False,
28402844
)
28412845
events = capture_events()
28422846

tests/integrations/langchain/test_langchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,6 +3018,7 @@ def test_langchain_message_truncation(sentry_init, capture_events):
30183018
integrations=[LangchainIntegration(include_prompts=True)],
30193019
traces_sample_rate=1.0,
30203020
send_default_pii=True,
3021+
stream_gen_ai_spans=False,
30213022
)
30223023
events = capture_events()
30233024

0 commit comments

Comments
 (0)