Skip to content

Commit c523e1e

Browse files
committed
Merge branch 'major/3.0' into ivana/major/drop-support-celery
2 parents fb24f3e + f16d440 commit c523e1e

24 files changed

Lines changed: 224 additions & 371 deletions

MIGRATION_GUIDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
2727
## Removed
2828

2929
- The SDK no longer supports Python 3.6. The oldest supported version is now 3.7.
30+
- Dropped support for Django versions below 2.0.
31+
- Dropped support for gevent versions below 20.9.
32+
- Dropped support for greenlet versions below 0.4.17.
3033
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
3134
- 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.
3235
- Transaction profiling and related code was removed.

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/populate_tox/releases.jsonl

Lines changed: 102 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sentry_sdk/_init_implementation.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import re
12
import warnings
23
from typing import TYPE_CHECKING
34

45
import sentry_sdk
6+
from sentry_sdk.utils import logger, parse_version
57

68
if TYPE_CHECKING:
79
from typing import Any, ContextManager, Optional
@@ -41,11 +43,32 @@ def __exit__(self, exc_type: "Any", exc_value: "Any", tb: "Any") -> None:
4143
c.close()
4244

4345

44-
def _check_python_deprecations() -> None:
45-
# Since we're likely to deprecate Python versions in the future, I'm keeping
46-
# this handy function around. Use this to detect the Python version used and
47-
# to output logger.warning()s if it's deprecated.
48-
pass
46+
def _check_version_deprecations() -> None:
47+
try:
48+
import gevent
49+
50+
gevent_version = tuple(
51+
int(part) for part in re.split(r"a|b|rc|\.", gevent.__version__)[:2]
52+
)
53+
if gevent_version < (20, 9):
54+
logger.warning(
55+
"sentry-sdk 3.x supports gevent 20.9.0 or newer. "
56+
"Please upgrade gevent or downgrade to sentry-sdk 2.x."
57+
)
58+
except Exception:
59+
pass
60+
61+
try:
62+
import greenlet
63+
64+
greenlet_version = parse_version(greenlet.__version__)
65+
if greenlet_version is not None and greenlet_version < (0, 4, 17):
66+
logger.warning(
67+
"sentry-sdk 3.x supports greenlet 0.4.17 or newer. "
68+
"Please upgrade greenlet or downgrade to sentry-sdk 2.x."
69+
)
70+
except Exception:
71+
pass
4972

5073

5174
def _init(*args: "Optional[str]", **kwargs: "Any") -> "ContextManager[Any]":
@@ -55,7 +78,7 @@ def _init(*args: "Optional[str]", **kwargs: "Any") -> "ContextManager[Any]":
5578
"""
5679
client = sentry_sdk.Client(*args, **kwargs)
5780
sentry_sdk.get_global_scope().set_client(client)
58-
_check_python_deprecations()
81+
_check_version_deprecations()
5982
rv = _InitGuard(client)
6083
return rv
6184

sentry_sdk/ai/monitoring.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import inspect
22
import sys
33
import warnings
4+
from contextvars import ContextVar
45
from functools import wraps
56
from typing import TYPE_CHECKING
67

@@ -11,14 +12,16 @@
1112
from sentry_sdk.traces import StreamedSpan
1213
from sentry_sdk.tracing import Span
1314
from sentry_sdk.tracing_utils import has_span_streaming_enabled
14-
from sentry_sdk.utils import ContextVar, capture_internal_exceptions, reraise
15+
from sentry_sdk.utils import capture_internal_exceptions, reraise
1516

1617
if TYPE_CHECKING:
1718
from typing import Any, Awaitable, Callable, Optional, TypeVar, Union
1819

1920
F = TypeVar("F", bound=Union[Callable[..., Any], Callable[..., Awaitable[Any]]])
2021

21-
_ai_pipeline_name = ContextVar("ai_pipeline_name", default=None)
22+
_ai_pipeline_name: "ContextVar[Optional[str]]" = ContextVar(
23+
"ai_pipeline_name", default=None
24+
)
2225

2326

2427
def set_ai_pipeline_name(name: "Optional[str]") -> None:

sentry_sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import uuid
88
import warnings
99
from collections.abc import Iterable, Mapping
10+
from contextvars import ContextVar
1011
from datetime import datetime, timezone
1112
from importlib import import_module
1213
from typing import TYPE_CHECKING, Dict, List, cast, overload
@@ -44,7 +45,6 @@
4445
)
4546
from sentry_sdk.utils import (
4647
AnnotatedValue,
47-
ContextVar,
4848
capture_internal_exceptions,
4949
current_stacktrace,
5050
datetime_from_isoformat,
@@ -87,7 +87,7 @@
8787

8888
I = TypeVar("I", bound=Integration) # noqa: E741
8989

90-
_client_init_debug = ContextVar("client_init_debug")
90+
_client_init_debug: "ContextVar[bool]" = ContextVar("client_init_debug")
9191

9292

9393
SDK_INFO: "SDKInfo" = {

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def iter_default_integrations(
135135
"chalice": (1, 16, 0),
136136
"clickhouse_driver": (0, 2, 0),
137137
"cohere": (5, 4, 0),
138-
"django": (1, 8),
138+
"django": (2, 0),
139139
"dramatiq": (1, 9),
140140
"falcon": (1, 4),
141141
"fastapi": (0, 79, 0),

sentry_sdk/integrations/aiohttp.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
should_propagate_trace,
4242
)
4343
from sentry_sdk.utils import (
44-
CONTEXTVARS_ERROR_MESSAGE,
45-
HAS_REAL_CONTEXTVARS,
4644
SENSITIVE_DATA_SUBSTITUTE,
4745
AnnotatedValue,
4846
_register_control_flow_exception,
@@ -108,14 +106,6 @@ def setup_once() -> None:
108106
version = parse_version(AIOHTTP_VERSION)
109107
_check_minimum_version(AioHttpIntegration, version)
110108

111-
if not HAS_REAL_CONTEXTVARS:
112-
# We better have contextvars or we're going to leak state between
113-
# requests.
114-
raise DidNotEnable(
115-
"The aiohttp integration for Sentry requires Python 3.7+ "
116-
" or aiocontextvars package." + CONTEXTVARS_ERROR_MESSAGE
117-
)
118-
119109
# In the aiohttp integration, all of their HTTP responses are Exceptions.
120110
# Because they have to be raised and handled by the framework, we need to
121111
# register the exceptions as control flow exceptions so that we don't

sentry_sdk/integrations/asgi.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import inspect
88
import sys
99
from contextlib import nullcontext
10+
from contextvars import ContextVar
1011
from copy import deepcopy
1112
from functools import partial
1213
from typing import TYPE_CHECKING
@@ -42,9 +43,6 @@
4243
)
4344
from sentry_sdk.tracing_utils import has_span_streaming_enabled
4445
from sentry_sdk.utils import (
45-
CONTEXTVARS_ERROR_MESSAGE,
46-
HAS_REAL_CONTEXTVARS,
47-
ContextVar,
4846
_get_installed_modules,
4947
capture_internal_exceptions,
5048
event_from_exception,
@@ -62,7 +60,9 @@
6260
from sentry_sdk.tracing import Span
6361

6462

65-
_asgi_middleware_applied = ContextVar("sentry_asgi_middleware_applied")
63+
_asgi_middleware_applied: "ContextVar[bool]" = ContextVar(
64+
"sentry_asgi_middleware_applied"
65+
)
6666

6767
_DEFAULT_TRANSACTION_NAME = "generic ASGI request"
6868

@@ -114,7 +114,6 @@ class SentryAsgiMiddleware:
114114
def __init__(
115115
self,
116116
app: "Any",
117-
unsafe_context_data: bool = False,
118117
transaction_style: str = "endpoint",
119118
mechanism_type: str = "asgi",
120119
span_origin: str = "manual",
@@ -127,15 +126,7 @@ def __init__(
127126
data to sent events and basic handling for exceptions bubbling up
128127
through the middleware.
129128
130-
:param unsafe_context_data: Disable errors when a proper contextvars installation could not be found. We do not recommend changing this from the default.
131129
"""
132-
if not unsafe_context_data and not HAS_REAL_CONTEXTVARS:
133-
# We better have contextvars or we're going to leak state between
134-
# requests.
135-
raise RuntimeError(
136-
"The ASGI middleware for Sentry requires Python 3.7+ "
137-
"or the aiocontextvars package." + CONTEXTVARS_ERROR_MESSAGE
138-
)
139130
if transaction_style not in TRANSACTION_STYLE_VALUES:
140131
raise ValueError(
141132
"Invalid value for transaction_style: %s (must be in %s)"

sentry_sdk/integrations/dedupe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import weakref
2+
from contextvars import ContextVar
23
from typing import TYPE_CHECKING
34

45
import sentry_sdk
56
from sentry_sdk.integrations import Integration
67
from sentry_sdk.scope import add_global_event_processor
7-
from sentry_sdk.utils import ContextVar, logger
8+
from sentry_sdk.utils import logger
89

910
if TYPE_CHECKING:
10-
from typing import Optional
11+
from typing import Any, Optional
1112

1213
from sentry_sdk._types import Event, Hint
1314

@@ -16,7 +17,7 @@ class DedupeIntegration(Integration):
1617
identifier = "dedupe"
1718

1819
def __init__(self) -> None:
19-
self._last_seen = ContextVar("last-seen")
20+
self._last_seen: "ContextVar[Any]" = ContextVar("last-seen")
2021

2122
@staticmethod
2223
def setup_once() -> None:

0 commit comments

Comments
 (0)