Skip to content

Commit a163f83

Browse files
committed
Do not set and then overwrite middlewares __call__
1 parent 63e0c67 commit a163f83

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

sentry_sdk/integrations/asgi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
if TYPE_CHECKING:
4444
from typing import Any
45-
from typing import Callable
4645
from typing import Dict
4746
from typing import Optional
4847
from typing import Tuple
@@ -102,6 +101,7 @@ def __init__(
102101
mechanism_type="asgi", # type: str
103102
span_origin="manual", # type: str
104103
http_methods_to_capture=DEFAULT_HTTP_METHODS_TO_CAPTURE, # type: Tuple[str, ...]
104+
asgi_version=None, # type: Optional[int]
105105
):
106106
# type: (...) -> None
107107
"""
@@ -140,9 +140,15 @@ def __init__(
140140
self.app = app
141141
self.http_methods_to_capture = http_methods_to_capture
142142

143-
if _looks_like_asgi3(app):
144-
self.__call__ = self._run_asgi3 # type: Callable[..., Any]
145-
else:
143+
if asgi_version is None:
144+
if _looks_like_asgi3(app):
145+
asgi_version = 3
146+
else:
147+
asgi_version = 2
148+
149+
if asgi_version == 3:
150+
self.__call__ = self._run_asgi3
151+
elif asgi_version == 2:
146152
self.__call__ = self._run_asgi2
147153

148154
def _capture_lifespan_exception(self, exc):

sentry_sdk/integrations/starlette.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ async def _sentry_patched_asgi_app(self, scope, receive, send):
403403
if integration
404404
else DEFAULT_HTTP_METHODS_TO_CAPTURE
405405
),
406+
asgi_version=3,
406407
)
407408

408-
middleware.__call__ = middleware._run_asgi3
409409
return await middleware(scope, receive, send)
410410

411411
Starlette.__call__ = _sentry_patched_asgi_app

0 commit comments

Comments
 (0)