Skip to content

Commit c1e4deb

Browse files
authored
Merge branch 'major/3.0' into ivana/otlp-remove-propagator
2 parents 48a5db2 + 4e6ab73 commit c1e4deb

20 files changed

Lines changed: 796 additions & 931 deletions

‎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 ✨

‎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

‎sentry_sdk/consts.py‎

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

20012001

2002-
VERSION = "3.0.0b3"
2002+
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
)

‎sentry_sdk/integrations/arq.py‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22
import time
3-
from datetime import timedelta, timezone
3+
from functools import wraps
44

55
import sentry_sdk
66
from sentry_sdk.consts import OP, SPANDATA
77
from sentry_sdk.crons import monitor
8+
from sentry_sdk.crons.utils import _get_timezone_name
89
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
910
from sentry_sdk.integrations.logging import ignore_logger_for_events
1011
from sentry_sdk.traces import SegmentNameSource
@@ -174,6 +175,7 @@ def event_processor(event: "Event", hint: "Hint") -> "Optional[Event]":
174175

175176

176177
def _wrap_coroutine(name: str, coroutine: "WorkerCoroutine") -> "WorkerCoroutine":
178+
@wraps(coroutine)
177179
async def _sentry_coroutine(
178180
ctx: "Dict[Any, Any]", *args: "Any", **kwargs: "Any"
179181
) -> "Any":
@@ -278,6 +280,9 @@ def _monitor_cron_job(
278280
return
279281
cron_job._sentry_monitored = True
280282

283+
if getattr(cron_job.coroutine, "_sentry_monitored", False):
284+
return
285+
281286
# arq names cron jobs "cron:<function name>" by default.
282287
monitor_slug = cron_job.name
283288
if monitor_slug.startswith("cron:"):
@@ -345,35 +350,23 @@ def _get_crontab(cron_job: "CronJob") -> "Optional[str]":
345350
return " ".join(fields) # type: ignore[arg-type]
346351

347352

348-
def _get_timezone_name(worker: "Worker") -> "Optional[str]":
353+
def _get_worker_timezone_name(worker: "Worker") -> "Optional[str]":
349354
tz = getattr(worker, "timezone", None)
350355
if tz is None:
351356
# Before arq 0.25, cron jobs ran in naive local time.
352357
if time.timezone == 0 and (not time.daylight or time.altzone == 0):
353358
return "UTC"
354359
return None
355360

356-
# zoneinfo and pytz
357-
name = getattr(tz, "key", None) or getattr(tz, "zone", None)
358-
if isinstance(name, str):
359-
return name
360-
361361
# arq defaults to the system's fixed UTC offset at startup.
362-
if isinstance(tz, timezone):
363-
offset = tz.utcoffset(None)
364-
if offset % timedelta(hours=1):
365-
return None
366-
hours = offset // timedelta(hours=1)
367-
return "Etc/GMT%+d" % -hours if hours else "UTC"
368-
369-
return None
362+
return _get_timezone_name(tz)
370363

371364

372365
def _get_monitor_config(
373366
cron_job: "CronJob", worker: "Worker"
374367
) -> "Optional[MonitorConfig]":
375368
crontab = _get_crontab(cron_job)
376-
timezone_name = _get_timezone_name(worker)
369+
timezone_name = _get_worker_timezone_name(worker)
377370
if crontab is None or timezone_name is None:
378371
return None
379372
return {

‎sentry_sdk/profiler/continuous_profiler.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ def ensure_running(self) -> None:
265265
def teardown(self) -> None:
266266
raise NotImplementedError
267267

268-
def pause(self) -> None:
269-
raise NotImplementedError
270-
271268
def reset_buffer(self) -> None:
272269
self.buffer = ProfileBuffer(
273270
self.options, self.sdk_info, PROFILE_BUFFER_SECONDS, self.capture_func

0 commit comments

Comments
 (0)