Skip to content

Commit e70b8e1

Browse files
committed
Merge branch 'major/3.0' into ivana/major/drop-experimental-options
2 parents 7fb06c5 + 948b307 commit e70b8e1

82 files changed

Lines changed: 4926 additions & 6235 deletions

Some content is hidden

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

.github/workflows/flaky-test-detector.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
# and the repo, and writes the issue body to flaky-issue-body.md.
109109
- name: Analyze logs and summarize flaky tests
110110
if: steps.collect.outputs.collected != '0'
111-
uses: anthropics/claude-code-action@1f291e1cfe0f5fc21db2aef19af844591600ade7 # v1.0.206
111+
uses: anthropics/claude-code-action@70fec183852c4f82f3f1969faed7dd60c5149ca7 # v1.0.207
112112
with:
113113
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
114114
github_token: ${{ github.token }}

MIGRATION_GUIDE.md

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,71 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
2424
- The UnraisableHookIntegration is now enabled by default.
2525
- We now don't suppress chained exceptions in the ASGI and asyncio integrations by default. The related `suppress_asgi_chained_exceptions` experimental option was removed.
2626
- In the AWS Lambda and GCP integrations, the message of the warning the SDK optionally emits if a function is about to time out has changed.
27+
- We changed the way we emit warnings. Deprecations will from now on be always emitted using `warnings.warn()`, while all other warnings will be emitted using `logger.warning()`.
28+
- `sentry_sdk.init()` can no longer be used as a context manager.
29+
30+
### Logging
31+
32+
- The standard library logging integration is not auto-enabled by default anymore. To continue using it, add it to the `integrations` list in your `sentry_sdk.init()`:
33+
34+
```python
35+
import sentry_sdk
36+
from sentry_sdk.integrations.logging import LoggingIntegration
37+
38+
sentry_sdk.init(
39+
integrations=[
40+
LoggingIntegration(),
41+
]
42+
)
43+
```
44+
45+
- The `level` integration option is now called `breadcrumb_level`.
46+
- The `sentry_logs_level` integration option is now called `level`.
47+
- The `capture_sentry_logs` option was removed. Use `level=None` to disable log capture.
48+
- The `ignore_logger` helper was renamed to `ignore_logger_for_events`.
49+
- The `ignore_logger_for_sentry_logs` helper was renamed to `ignore_logger`.
50+
- `SentryHandler` was removed. Use `EventHandler` instead.
51+
- When you enable the integration by adding `LoggingIntegration` to your `sentry_sdk.init()`, it'll start capturing Sentry logs and breadcrumbs. Creating events from logs can be enabled by providing additional integration options.
52+
53+
| Old name | New name | Old default | New default | Description |
54+
| --- | --- | --- | --- | --- |
55+
| `level` | `breadcrumb_level` | `INFO` | `INFO` | Captures logs of that level and higher as breadcrumbs. |
56+
| `event_level` | `event_level` | `ERROR` | `None` | Captures logs of that level and higher as events. |
57+
| `sentry_logs_level` | `level` | `INFO` | `INFO` | Captures logs of that level and higher as Sentry logs. |
58+
| `capture_sentry_logs` | removed | `False` | n/a | Allows to opt out of instrumenting logs as Sentry logs. Use `level` (previously `sentry_logs_level`) to adjust what should be captured instead. |
59+
| `ignore_logger` | `ignore_logger_for_events` | n/a | n/a | Loggers that match this name will not create breadcrumbs and events. |
60+
| `unignore_logger` | `unignore_logger_for_events` | n/a | n/a | Loggers that match this name will create breadcrumbs and events again. |
61+
| `ignore_logger_for_sentry_logs` | `ignore_logger` | n/a | n/a | Loggers that match this name will not create Sentry logs. |
62+
| `unignore_logger_for_sentry_logs` | `unignore_logger` | n/a | n/a | Loggers that match this name will create Sentry logs again. |
63+
64+
65+
### Loguru
66+
67+
- The Loguru logging integration is not auto-enabled by default anymore if you have Loguru installed. To continue using it, add it to the `integrations` list in your `sentry_sdk.init()`:
68+
69+
```python
70+
import sentry_sdk
71+
from sentry_sdk.integrations.loguru import LoguruIntegration
72+
73+
sentry_sdk.init(
74+
integrations=[
75+
LoguruIntegration(),
76+
]
77+
)
78+
```
79+
80+
- The `level` integration option is now called `breadcrumb_level`.
81+
- The `sentry_logs_level` integration option is now called `level`.
82+
- The `capture_sentry_logs` option was removed. Use `level=None` to disable log capture.
83+
- When you enable the integration by adding `LoguruIntegration` to your `sentry_sdk.init()`, it'll start capturing Sentry logs and breadcrumbs. Creating events from logs can be enabled by providing additional integration options.
84+
85+
| Old name | New name | Old default | New default | Description |
86+
| --- | --- | --- | --- | --- |
87+
| `level` | `breadcrumb_level` | `INFO` | `INFO` | Captures logs of that level and higher as breadcrumbs. |
88+
| `event_level` | `event_level` | `ERROR` | `None` | Captures logs of that level and higher as events. |
89+
| `sentry_logs_level` | `level` | `INFO` | `INFO` | Captures logs of that level and higher as Sentry logs. |
90+
| `capture_sentry_logs` | removed | `False` | n/a | Allows to opt out of instrumenting logs as Sentry logs. Use `level` (previously `sentry_logs_level`) to adjust what should be captured instead. |
91+
2792

2893
## Removed
2994

@@ -51,21 +116,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
51116
- Removed the RedisIntegration `max_data_size` option.
52117
- Removed the possibility to supply a specific client to the LaunchDarklyIntegration.
53118
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
54-
- The `enable_logs` option was removed. Using Sentry's logging API now works without requiring setting `enable_logs=True`. Automatic capture of logs emitted by the `logging` standard library module or Loguru can be turned on by providing the `capture_sentry_logs=True` option to either `LoggingIntegration` or `LoguruIntegration`:
55-
56-
```python
57-
import sentry_sdk
58-
from sentry_sdk.integrations.logging import LoggingIntegration
59-
from sentry_sdk.integrations.loguru import LoguruIntegration
60-
61-
sentry_sdk.init(
62-
integrations=[
63-
LoggingIntegration(capture_sentry_logs=True),
64-
LoguruIntegration(capture_sentry_logs=True),
65-
]
66-
)
67-
```
68-
119+
- The `enable_logs` option was removed. Using Sentry's logging API now works without requiring setting `enable_logs=True`.
69120
- The `enable_metrics` option was removed.
70121
- The deprecated `@ai_track` decorator was removed.
71122
- The deprecated `push_scope` and `configure_scope` APIs have been removed. Use `with new_scope():` to push a new scope and `scope = get_current_scope()` to retrieve the current scope instead.
@@ -87,9 +138,19 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
87138
- The experimental `before_send_metric` option was removed. Use the top-level `before_send_metric` instead.
88139
- The experimental `ignore_spans` option was removed. Use the top-level `ignore_spans` instead.
89140
- The experimental `before_send_span` option was removed. Use the top-level `before_send_span` instead.
141+
- `configure_debug_hub` was removed.
142+
- The `max_spans` option of the `LangchainIntegration` was removed.
143+
- `Baggage.from_options` was removed.
144+
- `Transport.capture_event` was removed. Use `Transport.capture_envelope` instead.
145+
- Function transports were removed.
146+
- The `Scope.trace_propagation_meta` function no longer accepts a `span` as argument.
147+
- Direct assignment to `Scope.level` was removed. Use `Scope.set_level` instead.
148+
- Direct assignment to `Scope.user` was removed. Use `Scope.set_user` instead.
149+
- `Scope.iter_headers` was removed.
90150
- The SDK won't set any tags on its own anymore.
91151
- The `update_current_span` API was removed.
92152

153+
93154
## Deprecated
94155

95156

sentry_sdk/_compat.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,26 @@ def enabled(option: str) -> bool:
6161
lazy_mode = enabled("lazy-apps") or enabled("lazy")
6262

6363
if lazy_mode and not threads_enabled:
64-
from warnings import warn
65-
66-
warn(
67-
Warning(
68-
"IMPORTANT: "
69-
"We detected the use of uWSGI without thread support. "
70-
"This might lead to unexpected issues. "
71-
'Please run uWSGI with "--enable-threads" for full support.'
72-
)
64+
from sentry_sdk.utils import logger
65+
66+
logger.warning(
67+
"IMPORTANT: "
68+
"We detected the use of uWSGI without thread support. "
69+
"This might lead to unexpected issues. "
70+
'Please run uWSGI with "--enable-threads" for full support.'
7371
)
7472

7573
return False
7674

7775
elif not lazy_mode and (not threads_enabled or not fork_hooks_on):
78-
from warnings import warn
79-
80-
warn(
81-
Warning(
82-
"IMPORTANT: "
83-
"We detected the use of uWSGI in preforking mode without "
84-
"thread support. This might lead to crashing workers. "
85-
'Please run uWSGI with both "--enable-threads" and '
86-
'"--py-call-uwsgi-fork-hooks" for full support.'
87-
)
76+
from sentry_sdk.utils import logger
77+
78+
logger.warning(
79+
"IMPORTANT: "
80+
"We detected the use of uWSGI in preforking mode without "
81+
"thread support. This might lead to crashing workers. "
82+
'Please run uWSGI with both "--enable-threads" and '
83+
'"--py-call-uwsgi-fork-hooks" for full support.'
8884
)
8985

9086
return False

sentry_sdk/_init_implementation.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
11
import re
2-
import warnings
32
from typing import TYPE_CHECKING
43

54
import sentry_sdk
65
from sentry_sdk.utils import logger, parse_version
76

87
if TYPE_CHECKING:
9-
from typing import Any, ContextManager, Optional
8+
from typing import Any, Optional
109

1110
import sentry_sdk.consts
1211

1312

14-
class _InitGuard:
15-
_CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE = (
16-
"Using the return value of sentry_sdk.init as a context manager "
17-
"and manually calling the __enter__ and __exit__ methods on the "
18-
"return value are deprecated. We are no longer maintaining this "
19-
"functionality, and we will remove it in the next major release."
20-
)
21-
22-
def __init__(self, client: "sentry_sdk.Client") -> None:
23-
self._client = client
24-
25-
def __enter__(self) -> "_InitGuard":
26-
warnings.warn(
27-
self._CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE,
28-
stacklevel=2,
29-
category=DeprecationWarning,
30-
)
31-
32-
return self
33-
34-
def __exit__(self, exc_type: "Any", exc_value: "Any", tb: "Any") -> None:
35-
warnings.warn(
36-
self._CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE,
37-
stacklevel=2,
38-
category=DeprecationWarning,
39-
)
40-
41-
c = self._client
42-
if c is not None:
43-
c.close()
44-
45-
4613
def _check_version_deprecations() -> None:
4714
try:
4815
import gevent
@@ -71,26 +38,23 @@ def _check_version_deprecations() -> None:
7138
pass
7239

7340

74-
def _init(*args: "Optional[str]", **kwargs: "Any") -> "ContextManager[Any]":
41+
def _init(*args: "Optional[str]", **kwargs: "Any") -> None:
7542
"""Initializes the SDK and optionally integrations.
7643
7744
This takes the same arguments as the client constructor.
7845
"""
7946
client = sentry_sdk.Client(*args, **kwargs)
8047
sentry_sdk.get_global_scope().set_client(client)
8148
_check_version_deprecations()
82-
rv = _InitGuard(client)
83-
return rv
8449

8550

8651
if TYPE_CHECKING:
8752
# Make mypy, PyCharm and other static analyzers think `init` is a type to
8853
# have nicer autocompletion for params.
8954
#
90-
# Use `ClientConstructor` to define the argument types of `init` and
91-
# `ContextManager[Any]` to tell static analyzers about the return type.
55+
# Use `ClientConstructor` to define the argument types of `init`.
9256

93-
class init(sentry_sdk.consts.ClientConstructor, _InitGuard): # noqa: N801
57+
class init(sentry_sdk.consts.ClientConstructor): # noqa: N801
9458
pass
9559

9660
else:

sentry_sdk/_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class DataCollectionUserOptions(TypedDict, total=False):
183183
gen_ai: "GenAICollectionUserOptions"
184184
database_query_data: bool
185185
queues: bool
186-
stack_frame_variables: bool
186+
stack_frame_variables: "Union[bool, KeyValueCollectionBehaviour]"
187187
frame_context_lines: int
188188

189189
class DataCollection(TypedDict):
@@ -197,7 +197,7 @@ class DataCollection(TypedDict):
197197
gen_ai: "GenAICollectionBehaviour"
198198
database_query_data: bool
199199
queues: bool
200-
stack_frame_variables: bool
200+
stack_frame_variables: "Union[bool, KeyValueCollectionBehaviour]"
201201
frame_context_lines: int
202202

203203
# "critical" is an alias of "fatal" recognized by Relay

sentry_sdk/client.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import socket
66
import sys
77
import uuid
8-
import warnings
98
from collections.abc import Iterable, Mapping
109
from contextvars import ContextVar
1110
from datetime import datetime, timezone
@@ -348,9 +347,8 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]":
348347
else rv["send_default_pii"]
349348
)
350349
elif has_data_collection_enabled(rv) and rv["event_scrubber"]:
351-
warnings.warn(
350+
logger.warning(
352351
"Event scrubbers are not enabled when data collection configuration is provided. Ignoring event_scrubber...",
353-
stacklevel=2,
354352
)
355353
rv["event_scrubber"] = None
356354

@@ -366,21 +364,18 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]":
366364
)
367365

368366
if rv["trace_ignore_status_codes"] and has_span_streaming_enabled(rv):
369-
warnings.warn(
367+
logger.warning(
370368
"The `trace_ignore_status_codes` parameter is ignored in span streaming mode.",
371-
stacklevel=2,
372369
)
373370

374371
if rv["ignore_spans"] and not has_span_streaming_enabled(rv):
375-
warnings.warn(
372+
logger.warning(
376373
"The `ignore_spans` parameter only works when `trace_lifecycle` is set to `stream`.",
377-
stacklevel=2,
378374
)
379375

380376
if rv["before_send_span"] and not has_span_streaming_enabled(rv):
381-
warnings.warn(
377+
logger.warning(
382378
"The `before_send_span` parameter only works when `trace_lifecycle` is set to `stream`.",
383-
stacklevel=2,
384379
)
385380

386381
return rv
@@ -1334,9 +1329,8 @@ def close(
13341329
"""
13351330
if self.transport is not None:
13361331
if self._has_async_transport():
1337-
warnings.warn(
1332+
logger.warning(
13381333
"close() used with AsyncHttpTransport. Use close_async() instead.",
1339-
stacklevel=2,
13401334
)
13411335
self._flush_components()
13421336
else:
@@ -1381,9 +1375,8 @@ def flush(
13811375
"""
13821376
if self.transport is not None:
13831377
if self._has_async_transport():
1384-
warnings.warn(
1378+
logger.warning(
13851379
"flush() used with AsyncHttpTransport. Use flush_async() instead.",
1386-
stacklevel=2,
13871380
)
13881381
return
13891382
if timeout is None:

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ def __init__(
12861286
in_app_exclude: "List[str]" = [], # noqa: B006
12871287
default_integrations: bool = True,
12881288
dist: "Optional[str]" = None,
1289-
transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]" = None,
1289+
transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], None]]" = None,
12901290
transport_queue_size: int = DEFAULT_QUEUE_SIZE,
12911291
sample_rate: float = 1.0,
12921292
send_default_pii: "Optional[bool]" = None,

0 commit comments

Comments
 (0)