Skip to content

Commit 438ded1

Browse files
merge major branch
2 parents 48eae1c + 88cea40 commit 438ded1

43 files changed

Lines changed: 4237 additions & 3570 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## 3.0.0b4
4+
5+
This is a pre-release of the next Python SDK major, to be released in November 2026.
6+
7+
Want to give it a spin? Be our guest and [let us know](https://github.com/getsentry/sentry-python/discussions) how it went!
8+
9+
### ✨ Notable Changes
10+
- Say goodbye to transactions: span streaming is now the default tracing model
11+
- The fine-grained `data_collection` supersedes the flat `send_default_pii`
12+
13+
### 🗞️ Resources
14+
- [2.x to 3.x migration guide](https://docs.sentry.io/platforms/python/migration/2.x-to-3.x)
15+
- [detailed changelog](https://github.com/getsentry/sentry-python/blob/major/3.0/MIGRATION_GUIDE.md)
16+
317
## 3.0.0b3
418

519
This is a pre-release of the next Python SDK major, to be released in November 2026.
@@ -42,6 +56,58 @@ Want to give it a spin? Be our guest and [let us know](https://github.com/getsen
4256
- [2.x to 3.x migration guide](https://docs.sentry.io/platforms/python/migration/2.x-to-3.x)
4357
- [detailed changelog](https://github.com/getsentry/sentry-python/blob/major/3.0/MIGRATION_GUIDE.md)
4458

59+
## 2.74.0
60+
61+
### New Features ✨
62+
63+
#### Anthropic
64+
65+
- Record reasoning parts in streaming output by @alexander-alderman-webb in [#8193](https://github.com/getsentry/sentry-python/pull/8193)
66+
- Record reasoning parts in nonstreaming output by @alexander-alderman-webb in [#8192](https://github.com/getsentry/sentry-python/pull/8192)
67+
68+
#### Other
69+
70+
- (typesafe) Handle inline images by @alexander-alderman-webb in [#8164](https://github.com/getsentry/sentry-python/pull/8164)
71+
72+
### Bug Fixes 🐛
73+
74+
#### Anthropic
75+
76+
- Preserve cached `_iterator` property by @alexander-alderman-webb in [#8163](https://github.com/getsentry/sentry-python/pull/8163)
77+
- Stop unpacking output arrays by @alexander-alderman-webb in [#8160](https://github.com/getsentry/sentry-python/pull/8160)
78+
79+
#### Other
80+
81+
- (aiohttp) Leave existing `baggage` header alone if it has existin… by @pabloDeputter in [#8116](https://github.com/getsentry/sentry-python/pull/8116)
82+
- (boto3) Adapt to botocore no longer signing baggage by @sentrivana in [#8113](https://github.com/getsentry/sentry-python/pull/8113)
83+
- (ci) Restrict pytest because of incompatibilities by @sentrivana in [#8140](https://github.com/getsentry/sentry-python/pull/8140)
84+
- (falcon) Handle integer HTTP statuses by @jap and @sentrivana in [#8139](https://github.com/getsentry/sentry-python/pull/8139)
85+
- (sampling) Respect incoming sample rate if not explicitly overridden by @sentrivana in [#8185](https://github.com/getsentry/sentry-python/pull/8185)
86+
- (tracing) Drop trailing comma when serializing baggage without third-party items by @alphasafal and @pabloDeputter in [#8119](https://github.com/getsentry/sentry-python/pull/8119)
87+
- (wsgi) Stop overwriting `server.address` by @alexander-alderman-webb in [#8171](https://github.com/getsentry/sentry-python/pull/8171)
88+
89+
### Internal Changes 🔧
90+
91+
#### Deps
92+
93+
- Lock file maintenance by @renovate in [#8055](https://github.com/getsentry/sentry-python/pull/8055)
94+
- Bump grpcio to 1.84.1 by @geoffg-sentry with @sentry-junior in [#8136](https://github.com/getsentry/sentry-python/pull/8136)
95+
- Bump uv to 0.13.5 by @geoffg-sentry with @sentry-junior in [#8135](https://github.com/getsentry/sentry-python/pull/8135)
96+
- Bump brotli to 1.2.1 by @geoffg-sentry with @sentry-junior in [#8122](https://github.com/getsentry/sentry-python/pull/8122)
97+
98+
#### Other
99+
100+
- (mcp) Remove unused select_mcp_transactions fixture by @sentrivana with @sentry-junior in [#8150](https://github.com/getsentry/sentry-python/pull/8150)
101+
- (release) Bump craft to 3.9.0 and update config by @BYK with @sentry-junior in [#8181](https://github.com/getsentry/sentry-python/pull/8181)
102+
- (sessions) Remove unused TERMINAL_SESSION_STATES constant by @sentrivana with @sentry-junior in [#8151](https://github.com/getsentry/sentry-python/pull/8151)
103+
- (starlette) Remove unused \_serialize_request_body_data helper by @sentry-junior in [#8146](https://github.com/getsentry/sentry-python/pull/8146)
104+
- (toxgen) Remove unused `get_file_hash()` and `get_last_updated()` helpers by @sentry-junior in [#8173](https://github.com/getsentry/sentry-python/pull/8173)
105+
- (tracing) Remove unused base64_stripped regex by @sentry-junior in [#8148](https://github.com/getsentry/sentry-python/pull/8148)
106+
- (utils) Remove unused to_timestamp helper and epoch constant by @sentry-junior in [#8147](https://github.com/getsentry/sentry-python/pull/8147)
107+
- 🤖 Update test matrix with new releases (11/02) by @sentrivana with @github-actions in [#8172](https://github.com/getsentry/sentry-python/pull/8172)
108+
- Upgrade `sphinx` and remove `packaging` upper bound by @alexander-alderman-webb in [#8183](https://github.com/getsentry/sentry-python/pull/8183)
109+
- Update test matrix with new releases (27/10) by @alexander-alderman-webb in [#8126](https://github.com/getsentry/sentry-python/pull/8126)
110+
45111
## 2.73.0
46112

47113
### New Features ✨

‎MIGRATION_GUIDE.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
5252
- Whether the MCP integration records tool arguments, tool results, and prompt contents is now controlled by `data_collection`'s new `mcp` setting (`{"inputs": bool, "outputs": bool}`, both `True` by default) instead of the `gen_ai` setting.
5353
- With `handled_tool_call_exceptions=True` (the default), the Pydantic AI integration now reports an error for every failed tool argument validation attempt, including retries. Previously, only one error was reported per tool call.
5454
- The Pydantic AI integration no longer sets the `gen_ai.response.streaming` span attribute.
55+
- The `OTLPIntegration` no longer sets up a propagator by default: `setup_propagator` now defaults to `False`. Distributed tracing now uses the propagators configured in OpenTelemetry (by default, W3C `traceparent` and `baggage`) instead of Sentry's `sentry-trace` and `baggage` headers. To get the old behavior back, set `OTLPIntegration(setup_propagator=True)`. To propagate both W3C and Sentry headers, set up the `SentryOTLPPropagator` manually instead:
56+
57+
```python
58+
from opentelemetry.propagate import set_global_textmap
59+
from opentelemetry.propagators.composite import CompositePropagator
60+
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
61+
62+
from sentry_sdk.integrations.otlp import SentryOTLPPropagator
63+
64+
set_global_textmap(
65+
CompositePropagator([TraceContextTextMapPropagator(), SentryOTLPPropagator()])
66+
)
67+
```
5568

5669
#### Span operation consolidation
5770

‎docs/conf.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
copyright = "2019-{}, Sentry Team and Contributors".format(datetime.now().year)
1818
author = "Sentry Team and Contributors"
1919

20-
release = "3.0.0b3"
20+
release = "3.0.0b4"
2121
version = ".".join(release.split(".")[:2]) # The short X.Y version.
2222

2323

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typing = [
8282
"openai-agents>=0.22.0",
8383
"mistralai>=2.10.1",
8484
"typesafe-sdk>=0.7.5",
85+
"mypy-boto3-bedrock-runtime>=1.43.62",
8586
]
8687
test = [
8788
"dataclasses ; python_full_version < '3.7'",

‎sentry_sdk/consts.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2019,4 +2019,4 @@ def _get_default_options() -> "dict[str, Any]":
20192019
del _get_default_options
20202020

20212021

2022-
VERSION = "3.0.0b3"
2022+
VERSION = "3.0.0b4"

‎sentry_sdk/crons/decorator.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async def inner(*args: "P.args", **kwargs: "P.kwargs") -> "R":
126126
with self:
127127
return await fn(*args, **kwargs)
128128

129+
inner._sentry_monitored = True # type: ignore[attr-defined]
129130
return inner
130131

131132
def _sync_wrapper(self, fn: "Callable[P, R]") -> "Callable[P, R]":
@@ -134,4 +135,5 @@ def inner(*args: "P.args", **kwargs: "P.kwargs") -> "R":
134135
with self:
135136
return fn(*args, **kwargs)
136137

138+
inner._sentry_monitored = True # type: ignore[attr-defined]
137139
return inner

‎sentry_sdk/crons/utils.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import re
2+
from datetime import timedelta, timezone
13
from typing import TYPE_CHECKING
24

35
if TYPE_CHECKING:
6+
from datetime import tzinfo
47
from typing import Optional, Tuple
58

69
from sentry_sdk._types import MonitorConfigSchedule, MonitorConfigScheduleUnit
@@ -27,3 +30,26 @@ def _get_interval_schedule(seconds: float) -> "Optional[MonitorConfigSchedule]":
2730
"unit": unit,
2831
}
2932
return None
33+
34+
35+
# IANA zone names start with an uppercase letter. This rejects names like
36+
# "local" or "localtime" that tzlocal can give a zone.
37+
_IANA_TIMEZONE_NAME = re.compile(r"[A-Z][A-Za-z0-9._+-]*(?:/[A-Za-z0-9._+-]+)*")
38+
39+
40+
def _get_timezone_name(tz: "tzinfo") -> "Optional[str]":
41+
"""
42+
Return the IANA name of the timezone, or None if it has none.
43+
"""
44+
name = getattr(tz, "key", None) or getattr(tz, "zone", None)
45+
if isinstance(name, str):
46+
return name if _IANA_TIMEZONE_NAME.fullmatch(name) else None
47+
48+
if isinstance(tz, timezone):
49+
offset = tz.utcoffset(None)
50+
if offset % timedelta(hours=1):
51+
return None
52+
hours = offset // timedelta(hours=1)
53+
return "Etc/GMT%+d" % -hours if hours else "UTC"
54+
55+
return None

‎sentry_sdk/integrations/anthropic.py‎

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
except ImportError:
5757
raise DidNotEnable("Anthropic not installed or incompatible")
5858

59+
try:
60+
from anthropic.types import ThinkingBlock, ThinkingDelta
61+
except ImportError:
62+
ThinkingBlock = None # type: ignore[assignment,misc]
63+
ThinkingDelta = None # type: ignore[assignment,misc]
64+
5965
if TYPE_CHECKING:
6066
from typing import (
6167
Any,
@@ -77,15 +83,15 @@
7783
ToolUnionParam,
7884
)
7985

80-
from sentry_sdk._types import TextPart
86+
from sentry_sdk._types import ReasoningPart, TextPart
8187

8288
class _PatchedRawMessageStream(Stream[Any]):
8389
_span: Span
8490
_integration: "AnthropicIntegration"
8591

8692
_model: Optional[ModelParam]
8793
_usage: "_RecordedUsage"
88-
_content_blocks: list[Any]
94+
_content_blocks: "list[dict[str, Any]]"
8995
_response_id: Optional[str]
9096
_finish_reason: Optional[str]
9197

@@ -95,7 +101,7 @@ class _PatchedMessageStream(MessageStream):
95101

96102
_model: Optional[ModelParam]
97103
_usage: "_RecordedUsage"
98-
_content_blocks: list[Any]
104+
_content_blocks: "list[dict[str, Any]]"
99105
_response_id: Optional[str]
100106
_finish_reason: Optional[str]
101107

@@ -105,7 +111,7 @@ class _PatchedRawAsyncMessageStream(AsyncStream[Any]):
105111

106112
_model: Optional[ModelParam]
107113
_usage: "_RecordedUsage"
108-
_content_blocks: list[Any]
114+
_content_blocks: "list[dict[str, Any]]"
109115
_response_id: Optional[str]
110116
_finish_reason: Optional[str]
111117

@@ -115,7 +121,7 @@ class _PatchedAsyncMessageStream(AsyncMessageStream):
115121

116122
_model: Optional[ModelParam]
117123
_usage: "_RecordedUsage"
118-
_content_blocks: list[Any]
124+
_content_blocks: "list[dict[str, Any]]"
119125
_response_id: Optional[str]
120126
_finish_reason: Optional[str]
121127

@@ -353,22 +359,32 @@ def _collect_ai_data(
353359
event: "MessageStreamEvent",
354360
model: "str | None",
355361
usage: "_RecordedUsage",
356-
content_blocks: "list[str]",
362+
content_blocks: "list[dict[str, Any]]",
357363
response_id: "str | None" = None,
358364
finish_reason: "str | None" = None,
359-
) -> "tuple[str | None, _RecordedUsage, list[str], str | None, str | None]":
365+
) -> "tuple[str | None, _RecordedUsage, list[dict[str, Any]], str | None, str | None]":
360366
"""
361367
Collect model information, token usage, and collect content blocks from the AI streaming response.
362368
"""
363369
with capture_internal_exceptions():
364370
if hasattr(event, "type"):
365371
if event.type == "content_block_start":
366-
pass
372+
if ThinkingBlock is not None and isinstance(
373+
event.content_block, ThinkingBlock
374+
):
375+
content_blocks.append({"type": "thinking", "thinking": ""})
376+
elif event.content_block.type in ("text", "tool_use"):
377+
content_blocks.append({"type": "text", "text": ""})
378+
else:
379+
content_blocks.append({"type": event.content_block.type})
367380
elif event.type == "content_block_delta":
368-
if hasattr(event.delta, "text"):
369-
content_blocks.append(event.delta.text)
381+
block = content_blocks[event.index]
382+
if ThinkingDelta is not None and isinstance(event.delta, ThinkingDelta):
383+
block["thinking"] += event.delta.thinking
384+
elif hasattr(event.delta, "text"):
385+
block["text"] += event.delta.text
370386
elif hasattr(event.delta, "partial_json"):
371-
content_blocks.append(event.delta.partial_json)
387+
block["text"] += event.delta.partial_json
372388
elif event.type == "content_block_stop":
373389
pass
374390

@@ -664,7 +680,7 @@ def _set_output_data(
664680
output_tokens: "int | None",
665681
cache_read_input_tokens: "int | None",
666682
cache_write_input_tokens: "int | None",
667-
content_blocks: "list[Any]",
683+
content_blocks: "list[dict[str, Any]]",
668684
response_id: "str | None" = None,
669685
finish_reason: "str | None" = None,
670686
) -> None:
@@ -678,30 +694,30 @@ def _set_output_data(
678694
span.set_attribute(SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, [finish_reason])
679695

680696
if sentry_sdk.get_client().options["data_collection"]["gen_ai"]["outputs"]:
681-
output_messages: "dict[str, list[Any]]" = {
682-
"response": [],
683-
"tool": [],
684-
}
697+
parts: "list[Union[TextPart, ReasoningPart]]" = []
698+
tool_calls = []
685699

686700
for output in content_blocks:
687701
if output["type"] == "text":
688-
output_messages["response"].append(output["text"])
702+
parts.append({"type": "text", "content": output["text"]})
703+
elif output["type"] == "thinking":
704+
parts.append({"type": "reasoning", "content": output["thinking"]})
689705
elif output["type"] == "tool_use":
690-
output_messages["tool"].append(output)
706+
tool_calls.append(output)
691707

692-
if len(output_messages["tool"]) > 0:
708+
if len(tool_calls) > 0:
693709
set_data_normalized(
694710
span,
695711
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS,
696-
output_messages["tool"],
712+
tool_calls,
697713
unpack=False,
698714
)
699715

700-
if len(output_messages["response"]) > 0:
716+
if len(parts) > 0:
701717
set_data_normalized(
702718
span,
703-
SPANDATA.GEN_AI_RESPONSE_TEXT,
704-
output_messages["response"],
719+
SPANDATA.GEN_AI_OUTPUT_MESSAGES,
720+
[{"role": "assistant", "parts": parts}],
705721
unpack=False,
706722
)
707723

@@ -977,7 +993,7 @@ def _set_streaming_output_data(
977993
integration: "AnthropicIntegration",
978994
model: "Optional[str]",
979995
usage: "_RecordedUsage",
980-
content_blocks: "list[str]",
996+
content_blocks: "list[dict[str, Any]]",
981997
response_id: "Optional[str]",
982998
finish_reason: "Optional[str]",
983999
) -> None:
@@ -1000,7 +1016,7 @@ def _set_streaming_output_data(
10001016
output_tokens=usage.output_tokens,
10011017
cache_read_input_tokens=usage.cache_read_input_tokens,
10021018
cache_write_input_tokens=usage.cache_write_input_tokens,
1003-
content_blocks=[{"text": "".join(content_blocks), "type": "text"}],
1019+
content_blocks=content_blocks,
10041020
response_id=response_id,
10051021
finish_reason=finish_reason,
10061022
)

0 commit comments

Comments
 (0)