diff --git a/sentry_sdk/integrations/django/__init__.py b/sentry_sdk/integrations/django/__init__.py index 6be0113241..0de8730cfe 100644 --- a/sentry_sdk/integrations/django/__init__.py +++ b/sentry_sdk/integrations/django/__init__.py @@ -321,10 +321,14 @@ def sentry_patched_drf_initial(self, request, *args, **kwargs): def _patch_channels(): # type: () -> None try: + # Django < 3.0 from channels.http import AsgiHandler # type: ignore except ImportError: - return - + try: + # DJango 3.0+ + from django.core.handlers.asgi import ASGIHandler as AsgiHandler + except ImportError: + return if not HAS_REAL_CONTEXTVARS: # We better have contextvars or we're going to leak state between # requests.