Skip to content

Commit 221f372

Browse files
authored
ref(sanic): Drop < 22 (#7045)
1 parent 286f3fb commit 221f372

8 files changed

Lines changed: 431 additions & 143 deletions

File tree

MIGRATION_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
3737
- Dropped support for Starlette below 0.20.
3838
- Dropped support for FastAPI below 0.85.
3939
- Dropped support for trytond below 5.4.
40+
- Dropped support for Sanic below 22.0.
4041
- Removed the possibility to supply a specific client to the LaunchDarklyIntegration.
4142
- The `enable_tracing` option was removed. Use `traces_sample_rate=1.0` instead.
4243
- 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.

scripts/populate_tox/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@
445445
"sanic": {
446446
"package": "sanic",
447447
"deps": {
448-
"*": ["websockets<11.0", "aiohttp"],
449-
">=22": ["sanic-testing"],
448+
"*": ["websockets<11.0", "aiohttp", "sanic-testing"],
449+
"<22.9": ["sanic-testing<22.9", "httpx<0.24"],
450450
# tracerite imports pkg_resources before https://github.com/sanic-org/tracerite/commit/2f68543fab726d12d5c5d71fab584eb42140f410
451451
"py3.8": ["tracerite<1.1.2", "setuptools<82"],
452452
},

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 54 additions & 7 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: 216 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def iter_default_integrations(
167167
"redis": (2, 10, 0),
168168
"requests": (2, 30, 0),
169169
"rq": (0, 6),
170-
"sanic": (0, 8),
170+
"sanic": (22, 0),
171171
"spark": (3, 0), # pyspark
172172
"sqlalchemy": (1, 4),
173173
"starlette": (0, 20),

sentry_sdk/integrations/sanic.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)
1414
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
1515
from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers
16-
from sentry_sdk.integrations.logging import ignore_logger
1716
from sentry_sdk.scope import should_send_default_pii
1817
from sentry_sdk.traces import SegmentNameSource, StreamedSpan
1918
from sentry_sdk.tracing import TransactionSource
@@ -78,22 +77,6 @@ def setup_once() -> None:
7877
SanicIntegration.version = parse_version(SANIC_VERSION)
7978
_check_minimum_version(SanicIntegration, SanicIntegration.version)
8079

81-
if SANIC_VERSION.startswith("0.8."):
82-
# Sanic 0.8 and older creates a logger named "root" and puts a
83-
# stringified version of every exception in there (without exc_info),
84-
# which our error deduplication can't detect.
85-
#
86-
# We explicitly check the version here because it is a very
87-
# invasive step to ignore this logger and not necessary in newer
88-
# versions at all.
89-
#
90-
# https://github.com/huge-success/sanic/issues/1332
91-
ignore_logger("root")
92-
93-
if SanicIntegration.version is not None and SanicIntegration.version < (21, 9):
94-
_setup_legacy_sanic()
95-
return
96-
9780
_setup_sanic()
9881

9982

@@ -130,12 +113,6 @@ def _setup_sanic() -> None:
130113
ErrorHandler.lookup = _sentry_error_handler_lookup
131114

132115

133-
def _setup_legacy_sanic() -> None:
134-
Sanic.handle_request = _legacy_handle_request
135-
Router.get = _legacy_router_get
136-
ErrorHandler.lookup = _sentry_error_handler_lookup
137-
138-
139116
async def _startup(self: "Sanic") -> None:
140117
# This happens about as early in the lifecycle as possible, just after the
141118
# Request object is created. The body has not yet been consumed.
@@ -300,54 +277,6 @@ async def sentry_wrapped_error_handler(
300277
return sentry_wrapped_error_handler
301278

302279

303-
async def _legacy_handle_request(
304-
self: "Any", request: "Request", *args: "Any", **kwargs: "Any"
305-
) -> "Any":
306-
if sentry_sdk.get_client().get_integration(SanicIntegration) is None:
307-
return await old_handle_request(self, request, *args, **kwargs)
308-
309-
weak_request = weakref.ref(request)
310-
311-
with sentry_sdk.isolation_scope() as scope:
312-
scope.clear_breadcrumbs()
313-
scope.add_event_processor(_make_request_processor(weak_request))
314-
315-
response = old_handle_request(self, request, *args, **kwargs)
316-
if isawaitable(response):
317-
response = await response
318-
319-
return response
320-
321-
322-
def _legacy_router_get(self: "Any", *args: "Union[Any, Request]") -> "Any":
323-
rv = old_router_get(self, *args)
324-
if sentry_sdk.get_client().get_integration(SanicIntegration) is not None:
325-
with capture_internal_exceptions():
326-
scope = sentry_sdk.get_isolation_scope()
327-
if SanicIntegration.version and SanicIntegration.version >= (21, 3):
328-
# Sanic versions above and including 21.3 append the app name to the
329-
# route name, and so we need to remove it from Route name so the
330-
# transaction name is consistent across all versions
331-
sanic_app_name = self.ctx.app.name
332-
sanic_route = rv[0].name
333-
334-
if sanic_route.startswith("%s." % sanic_app_name):
335-
# We add a 1 to the len of the sanic_app_name because there is a dot
336-
# that joins app name and the route name
337-
# Format: app_name.route_name
338-
sanic_route = sanic_route[len(sanic_app_name) + 1 :]
339-
340-
scope.set_transaction_name(
341-
sanic_route, source=TransactionSource.COMPONENT
342-
)
343-
else:
344-
scope.set_transaction_name(
345-
rv[0].__name__, source=TransactionSource.COMPONENT
346-
)
347-
348-
return rv
349-
350-
351280
@ensure_integration_enabled(SanicIntegration)
352281
def _capture_exception(exception: "Union[ExcInfo, BaseException]") -> None:
353282
with capture_internal_exceptions():

tests/integrations/sanic/test_sanic.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@ def simple_client(app):
8787
yield app.test_client
8888

8989
if ReusableClient is not None:
90-
return ReusableClient(app, port=get_free_port())
90+
91+
@contextlib.contextmanager
92+
def reusable_client(app):
93+
client = ReusableClient(app, port=get_free_port())
94+
client.__enter__()
95+
try:
96+
yield client
97+
finally:
98+
client.__exit__(None, None, None)
99+
100+
return reusable_client(app)
91101
else:
92102
return simple_client(app)
93103

0 commit comments

Comments
 (0)