8000 fix: Make patched channels asgi app awaitable, fix integraton-disabled codepath by untitaker · Pull Request #598 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

fix: Make patched channels asgi app awaitable, fix integraton-disabled codepath #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,22 +298,9 @@ def _patch_channels():
"Python 3.7+ or the aiocontextvars package from PyPI."
)

from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.integrations.django.asgi import patch_channels_asgi_handler_impl

old_app = AsgiHandler.__call__

def sentry_patched_asgi_handler(self, receive, send):
# type: (AsgiHandler, Any, Any) -> Any
if Hub.current.get_integration(DjangoIntegration) is None:
return old_app(receive, send)

middleware = SentryAsgiMiddleware(
lambda _scope: old_app.__get__(self, AsgiHandler)
)

return middleware(self.scope)(receive, send)

AsgiHandler.__call__ = sentry_patched_asgi_handler
patch_channels_asgi_handler_impl(AsgiHandler)


def _patch_django_asgi_handler():
Expand Down
16 changes: 16 additions & 0 deletions sentry_sdk/integrations/django/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ async def sentry_patched_asgi_handler(self, scope, receive, send):
return await middleware(scope, receive, send)

cls.__call__ = sentry_patched_asgi_handler


def patch_channels_asgi_handler_impl(cls):
# type: (Any) -> None
old_app = cls.__call__

async def sentry_patched_asgi_handler(self, receive, send):
# type: (Any, Any, Any) -> Any
if Hub.current.get_integration(DjangoIntegration) is None:
return await old_app(self, receive, send)

middleware = SentryAsgiMiddleware(lambda _scope: old_app.__get__(self, cls))

return await middleware(self.scope)(receive, send)

cls.__call__ = sentry_patched_asgi_handler
0