Skip to content
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

Add Sentry ASGI middleware #3357

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 17 additions & 2 deletions api/conf/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.conf import settings
from django.contrib.staticfiles.handlers import ASGIStaticFilesHandler

from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

from conf.asgi_handler import OpenverseASGIHandler


Expand All @@ -15,8 +17,21 @@ def get_asgi_application():
return OpenverseASGIHandler()


application = get_asgi_application()

# Give the base application a unique name so that it's easily referenced
# by other modules without needing to juggle through any of the various
# middlewares.
# For example, `ASGIStaticFileHandler` saves the application as
# `self.application`. However, `SentryAsgiMiddleware` saves it as `self.app`.
# If we relied on just referencing the pseudo-standard `application` exported
# in this module, we'd have to choose how to resolve the base application
# with the lifecycle handlers depending on what middleware was applied.
# Instead, we can just take advantage of the fact that these middleware
# all treat the passed-in application object as a singleton, so we're safe
# to directly reference `OPENVERSE_APPLICATION`, knowing that any middleware
# applied to it will be referencing the same application object in the end.
OPENVERSE_APPLICATION = get_asgi_application()
Comment on lines +20 to +32
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in anticipation of #3024, which is the primary reason we need the lifecycle callbacks.


application = SentryAsgiMiddleware(OPENVERSE_APPLICATION)

if settings.ENVIRONMENT == "local":
static_files_application = ASGIStaticFilesHandler(application)