Skip to content

Commit abf2976

Browse files
committed
chore: Drop even more deprecated stuff
1 parent a2ce2bb commit abf2976

File tree

5 files changed

+10
-176
lines changed

5 files changed

+10
-176
lines changed

MIGRATION_GUIDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
156156
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
157157
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
158158
- Function transports are no longer supported. Subclass the `Transport` instead.
159+
- Setting `Scope.transaction` directly is no longer supported. Use `Scope.set_transaction_name()` instead.
160+
- Passing a list or `None` for `failed_request_status_codes` in the Starlette integration is no longer supported. Pass a set of integers instead.
161+
- The `span` argument of `Scope.trace_propagation_meta` is no longer supported.
162+
- Setting `Scope.user` directly is no longer supported. Use `Scope.set_user()` instead.
159163

160164
### Deprecated
161165

sentry_sdk/integrations/_wsgi_common.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import sentry_sdk
55
from sentry_sdk.scope import should_send_default_pii
6-
from sentry_sdk.utils import AnnotatedValue, logger, SENSITIVE_DATA_SUBSTITUTE
6+
from sentry_sdk.utils import AnnotatedValue, SENSITIVE_DATA_SUBSTITUTE
77

88
try:
99
from django.http.request import RawPostDataException
@@ -19,7 +19,7 @@
1919
from typing import MutableMapping
2020
from typing import Optional
2121
from typing import Union
22-
from sentry_sdk._types import Event, HttpStatusCodeRange
22+
from sentry_sdk._types import Event
2323

2424

2525
SENSITIVE_ENV_KEYS = (
@@ -240,37 +240,3 @@ def _request_headers_to_span_attributes(headers):
240240
attributes[f"http.request.header.{header.lower()}"] = value
241241

242242
return attributes
243-
244-
245-
def _in_http_status_code_range(code, code_ranges):
246-
# type: (object, list[HttpStatusCodeRange]) -> bool
247-
for target in code_ranges:
248-
if isinstance(target, int):
249-
if code == target:
250-
return True
251-
continue
252-
253-
try:
254-
if code in target:
255-
return True
256-
except TypeError:
257-
logger.warning(
258-
"failed_request_status_codes has to be a list of integers or containers"
259-
)
260-
261-
return False
262-
263-
264-
class HttpCodeRangeContainer:
265-
"""
266-
Wrapper to make it possible to use list[HttpStatusCodeRange] as a Container[int].
267-
Used for backwards compatibility with the old `failed_request_status_codes` option.
268-
"""
269-
270-
def __init__(self, code_ranges):
271-
# type: (list[HttpStatusCodeRange]) -> None
272-
self._code_ranges = code_ranges
273-
274-
def __contains__(self, item):
275-
# type: (object) -> bool
276-
return _in_http_status_code_range(item, self._code_ranges)

sentry_sdk/integrations/starlette.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import functools
3-
import warnings
43
from collections.abc import Set
54
from copy import deepcopy
65

@@ -13,7 +12,6 @@
1312
)
1413
from sentry_sdk.integrations._wsgi_common import (
1514
DEFAULT_HTTP_METHODS_TO_CAPTURE,
16-
HttpCodeRangeContainer,
1715
_is_json_content_type,
1816
request_body_within_bounds,
1917
)
@@ -36,9 +34,9 @@
3634
from typing import TYPE_CHECKING
3735

3836
if TYPE_CHECKING:
39-
from typing import Any, Awaitable, Callable, Container, Dict, Optional, Tuple, Union
37+
from typing import Any, Awaitable, Callable, Dict, Optional, Tuple
4038

41-
from sentry_sdk._types import Event, HttpStatusCodeRange
39+
from sentry_sdk._types import Event
4240

4341
try:
4442
import starlette # type: ignore
@@ -88,7 +86,7 @@ class StarletteIntegration(Integration):
8886
def __init__(
8987
self,
9088
transaction_style="url", # type: str
91-
failed_request_status_codes=_DEFAULT_FAILED_REQUEST_STATUS_CODES, # type: Union[Set[int], list[HttpStatusCodeRange], None]
89+
failed_request_status_codes=_DEFAULT_FAILED_REQUEST_STATUS_CODES, # type: Set[int]
9290
middleware_spans=True, # type: bool
9391
http_methods_to_capture=DEFAULT_HTTP_METHODS_TO_CAPTURE, # type: tuple[str, ...]
9492
):
@@ -102,24 +100,7 @@ def __init__(
102100
self.middleware_spans = middleware_spans
103101
self.http_methods_to_capture = tuple(map(str.upper, http_methods_to_capture))
104102

105-
if isinstance(failed_request_status_codes, Set):
106-
self.failed_request_status_codes = (
107-
failed_request_status_codes
108-
) # type: Container[int]
109-
else:
110-
warnings.warn(
111-
"Passing a list or None for failed_request_status_codes is deprecated. "
112-
"Please pass a set of int instead.",
113-
DeprecationWarning,
114-
stacklevel=2,
115-
)
116-
117-
if failed_request_status_codes is None:
118-
self.failed_request_status_codes = _DEFAULT_FAILED_REQUEST_STATUS_CODES
119-
else:
120-
self.failed_request_status_codes = HttpCodeRangeContainer(
121-
failed_request_status_codes
122-
)
103+
self.failed_request_status_codes = failed_request_status_codes
123104

124105
@staticmethod
125106
def setup_once():

sentry_sdk/scope.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,6 @@ def trace_propagation_meta(self, *args, **kwargs):
561561
Return meta tags which should be injected into HTML templates
562562
to allow propagation of trace information.
563563
"""
564-
span = kwargs.pop("span", None)
565-
if span is not None:
566-
warnings.warn(
567-
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.",
568-
DeprecationWarning,
569-
stacklevel=2,
570-
)
571-
572564
meta = ""
573565

574566
sentry_trace = self.get_traceparent()
@@ -719,33 +711,6 @@ def transaction(self):
719711
# transaction) or a non-orphan span on the scope
720712
return self._span.containing_transaction
721713

722-
@transaction.setter
723-
def transaction(self, value):
724-
# type: (Any) -> None
725-
# would be type: (Optional[str]) -> None, see https://github.com/python/mypy/issues/3004
726-
"""When set this forces a specific transaction name to be set.
727-
728-
Deprecated: use set_transaction_name instead."""
729-
730-
# XXX: the docstring above is misleading. The implementation of
731-
# apply_to_event prefers an existing value of event.transaction over
732-
# anything set in the scope.
733-
# XXX: note that with the introduction of the Scope.transaction getter,
734-
# there is a semantic and type mismatch between getter and setter. The
735-
# getter returns a Span, the setter sets a transaction name.
736-
# Without breaking version compatibility, we could make the setter set a
737-
# transaction name or transaction (self._span) depending on the type of
738-
# the value argument.
739-
740-
warnings.warn(
741-
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead.",
742-
DeprecationWarning,
743-
stacklevel=2,
744-
)
745-
self._transaction = value
746-
if self._span and self._span.containing_transaction:
747-
self._span.containing_transaction.name = value
748-
749714
def set_transaction_name(self, name, source=None):
750715
# type: (str, Optional[str]) -> None
751716
"""Set the transaction name and optionally the transaction source."""
@@ -769,12 +734,6 @@ def transaction_source(self):
769734
# type: () -> Optional[str]
770735
return self._transaction_info.get("source")
771736

772-
@_attr_setter
773-
def user(self, value):
774-
# type: (Optional[Dict[str, Any]]) -> None
775-
"""When set a specific user is bound to the scope. Deprecated in favor of set_user."""
776-
self.set_user(value)
777-
778737
def set_user(self, value):
779738
# type: (Optional[Dict[str, Any]]) -> None
780739
"""Sets a user for the scope."""

tests/integrations/starlette/test_starlette.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,82 +1182,6 @@ def test_span_origin(sentry_init, capture_events):
11821182
assert span["origin"] == "auto.http.starlette"
11831183

11841184

1185-
class NonIterableContainer:
1186-
"""Wraps any container and makes it non-iterable.
1187-
1188-
Used to test backwards compatibility with our old way of defining failed_request_status_codes, which allowed
1189-
passing in a list of (possibly non-iterable) containers. The Python standard library does not provide any built-in
1190-
non-iterable containers, so we have to define our own.
1191-
"""
1192-
1193-
def __init__(self, inner):
1194-
self.inner = inner
1195-
1196-
def __contains__(self, item):
1197-
return item in self.inner
1198-
1199-
1200-
parametrize_test_configurable_status_codes_deprecated = pytest.mark.parametrize(
1201-
"failed_request_status_codes,status_code,expected_error",
1202-
[
1203-
(None, 500, True),
1204-
(None, 400, False),
1205-
([500, 501], 500, True),
1206-
([500, 501], 401, False),
1207-
([range(400, 499)], 401, True),
1208-
([range(400, 499)], 500, False),
1209-
([range(400, 499), range(500, 599)], 300, False),
1210-
([range(400, 499), range(500, 599)], 403, True),
1211-
([range(400, 499), range(500, 599)], 503, True),
1212-
([range(400, 403), 500, 501], 401, True),
1213-
([range(400, 403), 500, 501], 405, False),
1214-
([range(400, 403), 500, 501], 501, True),
1215-
([range(400, 403), 500, 501], 503, False),
1216-
([], 500, False),
1217-
([NonIterableContainer(range(500, 600))], 500, True),
1218-
([NonIterableContainer(range(500, 600))], 404, False),
1219-
],
1220-
)
1221-
"""Test cases for configurable status codes (deprecated API).
1222-
Also used by the FastAPI tests.
1223-
"""
1224-
1225-
1226-
@parametrize_test_configurable_status_codes_deprecated
1227-
def test_configurable_status_codes_deprecated(
1228-
sentry_init,
1229-
capture_events,
1230-
failed_request_status_codes,
1231-
status_code,
1232-
expected_error,
1233-
):
1234-
with pytest.warns(DeprecationWarning):
1235-
starlette_integration = StarletteIntegration(
1236-
failed_request_status_codes=failed_request_status_codes
1237-
)
1238-
1239-
sentry_init(integrations=[starlette_integration])
1240-
1241-
events = capture_events()
1242-
1243-
async def _error(request):
1244-
raise HTTPException(status_code)
1245-
1246-
app = starlette.applications.Starlette(
1247-
routes=[
1248-
starlette.routing.Route("/error", _error, methods=["GET"]),
1249-
],
1250-
)
1251-
1252-
client = TestClient(app)
1253-
client.get("/error")
1254-
1255-
if expected_error:
1256-
assert len(events) == 1
1257-
else:
1258-
assert not events
1259-
1260-
12611185
@pytest.mark.skipif(
12621186
STARLETTE_VERSION < (0, 21),
12631187
reason="Requires Starlette >= 0.21, because earlier versions do not support HTTP 'HEAD' requests",

0 commit comments

Comments
 (0)