Skip to content

Commit 87f099d

Browse files
committed
Merge branch 'major/3.0' into ivana/major/remove-transactions-django
2 parents 6215d7a + a7e8778 commit 87f099d

26 files changed

Lines changed: 375 additions & 401 deletions

MIGRATION_GUIDE.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ 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.
2729

2830
### Logging
2931

@@ -43,7 +45,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
4345
- The `level` integration option is now called `breadcrumb_level`.
4446
- The `sentry_logs_level` integration option is now called `level`.
4547
- The `capture_sentry_logs` option was removed. Use `level=None` to disable log capture.
46-
- The `ignore_logger` helper was renamed to `ignore_logger_for_breadcrumbs_and_events`.
48+
- The `ignore_logger` helper was renamed to `ignore_logger_for_events`.
4749
- The `ignore_logger_for_sentry_logs` helper was renamed to `ignore_logger`.
4850
- `SentryHandler` was removed. Use `EventHandler` instead.
4951
- 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.
@@ -114,21 +116,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
114116
- Removed the RedisIntegration `max_data_size` option.
115117
- Removed the possibility to supply a specific client to the LaunchDarklyIntegration.
116118
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
117-
- 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`:
118-
119-
```python
120-
import sentry_sdk
121-
from sentry_sdk.integrations.logging import LoggingIntegration
122-
from sentry_sdk.integrations.loguru import LoguruIntegration
123-
124-
sentry_sdk.init(
125-
integrations=[
126-
LoggingIntegration(capture_sentry_logs=True),
127-
LoguruIntegration(capture_sentry_logs=True),
128-
]
129-
)
130-
```
131-
119+
- The `enable_logs` option was removed. Using Sentry's logging API now works without requiring setting `enable_logs=True`.
132120
- The `enable_metrics` option was removed.
133121
- The deprecated `@ai_track` decorator was removed.
134122
- 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.
@@ -145,9 +133,19 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
145133
- The deprecated `propagate_traces` option has been removed. Use `trace_propagation_targets` instead, which gives you more power over trace propagation. Note that only the top-level `init` option was removed; the `propagate_traces` option of the Celery integration remains available.
146134
- Removed Spotlight integration for Django. See [Spotlight 2.0](https://github.com/getsentry/spotlight/issues/891) for more context.
147135
- The deprecated parameter `propagate_hub` in `ThreadingIntegration()` was removed.
136+
- `configure_debug_hub` was removed.
137+
- The `max_spans` option of the `LangchainIntegration` was removed.
138+
- `Baggage.from_options` was removed.
139+
- `Transport.capture_event` was removed. Use `Transport.capture_envelope` instead.
140+
- Function transports were removed.
141+
- The `Scope.trace_propagation_meta` function no longer accepts a `span` as argument.
142+
- Direct assignment to `Scope.level` was removed. Use `Scope.set_level` instead.
143+
- Direct assignment to `Scope.user` was removed. Use `Scope.set_user` instead.
144+
- `Scope.iter_headers` was removed.
148145
- The SDK won't set any tags on its own anymore.
149146
- The `update_current_span` API was removed.
150147

148+
151149
## Deprecated
152150

153151

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
@@ -1293,7 +1293,7 @@ def __init__(
12931293
in_app_exclude: "List[str]" = [], # noqa: B006
12941294
default_integrations: bool = True,
12951295
dist: "Optional[str]" = None,
1296-
transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]" = None,
1296+
transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], None]]" = None,
12971297
transport_queue_size: int = DEFAULT_QUEUE_SIZE,
12981298
sample_rate: float = 1.0,
12991299
send_default_pii: "Optional[bool]" = None,

sentry_sdk/data_collection.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
``DeprecationWarning`` is emitted for ``send_default_pii``.
2323
"""
2424

25-
import warnings
26-
from typing import TYPE_CHECKING, List, Mapping, Optional, Union, cast
25+
from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, Union, cast
2726
from urllib.parse import parse_qs, urlencode
2827

2928
from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE
29+
from sentry_sdk.utils import deprecation_warning
3030

3131
if TYPE_CHECKING:
32-
from typing import Any, Dict
33-
3432
from sentry_sdk._types import (
3533
DataCollection,
3634
GenAICollectionBehaviour,
@@ -190,29 +188,33 @@ def _map_from_send_default_pii(
190188

191189
def _resolve_explicit(
192190
d: "dict[str, Any]",
193-
include_local_variables: bool,
194-
include_source_context: bool,
195191
) -> "DataCollection":
196192
"""
197193
Build a fully-resolved ``DataCollection`` from a user-supplied
198194
``data_collection`` dict, filling in spec defaults for any omitted or
199-
partially-specified field. Frame fields fall back to the legacy
200-
``include_local_variables`` / ``include_source_context`` options when unset.
195+
partially-specified field.
201196
"""
202197
# frame_context_lines accepts an integer or a boolean fallback (spec: True
203198
# -> platform default of 5, False -> 0). bool is a subclass of int, so
204199
# coerce explicitly before treating it as a line count.
205200
frame_context_lines = d.get("frame_context_lines")
206201
if frame_context_lines is None:
207-
frame_context_lines = (
208-
_DEFAULT_FRAME_CONTEXT_LINES if include_source_context else 0
209-
)
202+
frame_context_lines = _DEFAULT_FRAME_CONTEXT_LINES
210203
elif isinstance(frame_context_lines, bool):
211204
frame_context_lines = _DEFAULT_FRAME_CONTEXT_LINES if frame_context_lines else 0
205+
else:
206+
if not isinstance(frame_context_lines, int) or frame_context_lines < 0:
207+
raise ValueError(
208+
"Invalid `frame_context_lines` value: Must be 0 or greater."
209+
)
210+
211+
raw_stack_frame_variables = d.get("stack_frame_variables", True)
212+
stack_frame_variables: "Union[bool, KeyValueCollectionBehaviour]"
212213

213-
stack_frame_variables = d.get("stack_frame_variables")
214-
if stack_frame_variables is None:
215-
stack_frame_variables = include_local_variables
214+
if isinstance(raw_stack_frame_variables, dict):
215+
stack_frame_variables = _kvcb_from_value(raw_stack_frame_variables)
216+
else:
217+
stack_frame_variables = bool(raw_stack_frame_variables)
216218

217219
# http_bodies: omitted means "all valid types"; [] is the explicit opt-out.
218220
http_bodies = d.get("http_bodies")
@@ -315,16 +317,12 @@ def _resolve_data_collection(options: "Dict[str, Any]") -> "DataCollection":
315317
)
316318
)
317319
if send_default_pii is not None:
318-
warnings.warn(
320+
deprecation_warning(
319321
"`send_default_pii` is deprecated and ignored when "
320322
"`data_collection` is set.",
321-
DeprecationWarning,
322-
stacklevel=2,
323323
)
324324
return _resolve_explicit(
325325
user_dc,
326-
include_local_variables,
327-
include_source_context,
328326
)
329327

330328
return _map_from_send_default_pii(

sentry_sdk/debug.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import sys
3-
import warnings
43
from logging import LogRecord
54

65
from sentry_sdk import get_client
@@ -27,11 +26,3 @@ def configure_logger() -> None:
2726
logger.addHandler(_handler)
2827
logger.setLevel(logging.DEBUG)
2928
logger.addFilter(_DebugFilter())
30-
31-
32-
def configure_debug_hub() -> None:
33-
warnings.warn(
34-
"configure_debug_hub is deprecated. Please remove calls to it, as it is a no-op.",
35-
DeprecationWarning,
36-
stacklevel=2,
37-
)

0 commit comments

Comments
 (0)