@@ -53,22 +53,30 @@ async def sentry_patched_get_response_async(self, request):
53
53
def patch_channels_asgi_handler_impl (cls ):
54
54
# type: (Any) -> None
55
55
56
+ import channels # type: ignore
56
57
from sentry_sdk .integrations .django import DjangoIntegration
57
58
58
- old_app = cls . __call__
59
+ if channels . __version__ < "3.0.0" :
59
60
60
- async def sentry_patched_asgi_handler (self , receive , send ):
61
- # type: (Any, Any, Any) -> Any
62
- if Hub .current .get_integration (DjangoIntegration ) is None :
63
- return await old_app (self , receive , send )
61
+ old_app = cls .__call__
64
62
65
- middleware = SentryAsgiMiddleware (
66
- lambda _scope : old_app .__get__ (self , cls ), unsafe_context_data = True
67
- )
63
+ async def sentry_patched_asgi_handler (self , receive , send ):
64
+ # type: (Any, Any, Any) -> Any
65
+ if Hub .current .get_integration (DjangoIntegration ) is None :
66
+ return await old_app (self , receive , send )
68
67
69
- return await middleware (self .scope )(receive , send )
68
+ middleware = SentryAsgiMiddleware (
69
+ lambda _scope : old_app .__get__ (self , cls ), unsafe_context_data = True
70
+ )
70
71
71
- cls .__call__ = sentry_patched_asgi_handler
72
+ return await middleware (self .scope )(receive , send )
73
+
74
+ cls .__call__ = sentry_patched_asgi_handler
75
+
76
+ else :
77
+ # The ASGI handler in Channels >= 3 has the same signature as
78
+ # the Django handler.
79
+ patch_django_asgi_handler_impl (cls )
72
80
73
81
74
82
def wrap_async_view (hub , callback ):
0 commit comments