sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Docs: Integration with Django ASGI + Channels Websockets

Open Laityned opened this issue 2 years ago • 3 comments

Problem Statement

This Python SDK has support for django ASGI.  We noted that in this integration therer is a check for django channels and depending on that setup the SDK.

Currently, we use besides the django channels HTTP requests also the websockets.  We did set it up as described here: channels routing docs 

However, we noted that the sentry SDK is capturing the logs of the django_asgi_app and not the websocket requests.

Therefore, we currently circumvented this problem by wrapping the websockets inside the SentryASGIMiddleware.

application = ProtocolTypeRouter(
    {
        "http": get_asgi_application(),
        "websocket": SentryAsgiMiddleware(
            URLRouter(routing.websocket_urlpatterns)
        ),
    }
)

This should probably documented in the documentation of sentry to include these detail that it is only capturing of the http requests of django channels.

Futhermore, are were curious if this is the way to go or that a better integration is available. In our dashboard, we see now everything logged as generic asgi request for websocket connection instead of the usual transaction name and doubting if the SQL performance issues are logged as well.

Solution Brainstorm

Update the docs to highlight the limitation of the current django integration in combination with django channels websockets.

Any suggestions how to provide more information in the integration SentryASGIMiddleware is welcome as well

Laityned avatar Dec 01 '23 11:12 Laityned

Hey @Laityned ! Thanks for reporting this. We will have a look.

antonpirker avatar Dec 01 '23 13:12 antonpirker

@Laityned - I'm following this thread as well, since we are doing the same...

ericmeadows avatar May 25 '24 22:05 ericmeadows

Hey folks, we haven't had time to look at this yet but PRs are always welcome, also against our docs repo. There's a handy link at the bottom of each docs page (for example https://docs.sentry.io/platforms/python/integrations/django/#install) that takes you directly to the correct file on GitHub to propose a change.

sentrivana avatar May 28 '24 10:05 sentrivana