From 2b0779b26a2578aeb7a22aad88b4246dcecf0718 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 Aug 2022 12:49:46 +0100 Subject: [PATCH] Install sentry --- requirements/base.in | 1 + requirements/base.txt | 5 +++-- requirements/dev.txt | 5 +++-- website/settings.py | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/requirements/base.in b/requirements/base.in index e922b7c..f46dc73 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -19,3 +19,4 @@ wagtail-metadata humanize drf-yasg django-plausible +sentry-sdk diff --git a/requirements/base.txt b/requirements/base.txt index 17efe08..d6361ea 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -9,7 +9,7 @@ asgiref==3.5.2 # via django async-timeout==4.0.2 # via redis beautifulsoup4==4.9.3 # via -r requirements/base.in, wagtail brotli==1.0.9 # via whitenoise -certifi==2022.6.15 # via requests +certifi==2022.6.15 # via requests, sentry-sdk charset-normalizer==2.1.0 # via requests click==8.1.3 # via rq coreapi==2.3.3 # via drf-yasg @@ -53,13 +53,14 @@ requests==2.28.1 # via -r requirements/base.in, coreapi, wagtail, wagta rq==1.10.1 # via django-rq ruamel-yaml==0.17.21 # via drf-yasg ruamel-yaml-clib==0.2.6 # via ruamel-yaml +sentry-sdk==1.9.5 # via -r requirements/base.in six==1.16.0 # via html5lib, l18n soupsieve==2.3.2.post1 # via beautifulsoup4 sqlparse==0.4.2 # via django tablib[xls,xlsx]==3.2.1 # via wagtail telepath==0.2 # via wagtail uritemplate==4.1.1 # via coreapi, drf-yasg -urllib3==1.26.11 # via requests +urllib3==1.26.11 # via requests, sentry-sdk wagtail==3.0.1 # via -r requirements/base.in, wagtail-draftail-snippet, wagtail-metadata wagtail-draftail-snippet==0.4.1 # via -r requirements/base.in wagtail-generic-chooser==0.4.1 # via -r requirements/base.in diff --git a/requirements/dev.txt b/requirements/dev.txt index 010bd34..f8138d7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,7 +12,7 @@ beautifulsoup4==4.9.3 # via -r requirements/base.txt, wagtail black==22.6.0 # via -r requirements/dev.in brotli==1.0.9 # via -r requirements/base.txt, whitenoise build==0.8.0 # via pip-tools -certifi==2022.6.15 # via -r requirements/base.txt, requests +certifi==2022.6.15 # via -r requirements/base.txt, requests, sentry-sdk charset-normalizer==2.1.0 # via -r requirements/base.txt, requests click==8.1.3 # via -r requirements/base.txt, black, curlylint, pip-tools, rq coreapi==2.3.3 # via -r requirements/base.txt, drf-yasg @@ -77,6 +77,7 @@ requests==2.28.1 # via -r requirements/base.txt, coreapi, wagtail, wagt rq==1.10.1 # via -r requirements/base.txt, django-rq ruamel-yaml==0.17.21 # via -r requirements/base.txt, drf-yasg ruamel-yaml-clib==0.2.6 # via -r requirements/base.txt, ruamel-yaml +sentry-sdk==1.9.5 # via -r requirements/base.txt six==1.16.0 # via -r requirements/base.txt, html5lib, l18n, python-dateutil soupsieve==2.3.2.post1 # via -r requirements/base.txt, beautifulsoup4 sqlparse==0.4.2 # via -r requirements/base.txt, django, django-debug-toolbar @@ -88,7 +89,7 @@ types-requests==2.28.5 # via -r requirements/dev.in types-urllib3==1.26.17 # via types-requests typing-extensions==4.3.0 # via mypy uritemplate==4.1.1 # via -r requirements/base.txt, coreapi, drf-yasg -urllib3==1.26.11 # via -r requirements/base.txt, requests +urllib3==1.26.11 # via -r requirements/base.txt, requests, sentry-sdk wagtail==3.0.1 # via -r requirements/base.txt, wagtail-draftail-snippet, wagtail-factories, wagtail-metadata wagtail-draftail-snippet==0.4.1 # via -r requirements/base.txt wagtail-factories==3.1.0 # via -r requirements/dev.in diff --git a/website/settings.py b/website/settings.py index 68fead9..04d7ff9 100644 --- a/website/settings.py +++ b/website/settings.py @@ -11,6 +11,8 @@ env = environ.Env( UNSPLASH_CLIENT_ID=(str, ""), SPOTIFY_PROXY_HOST=(str, ""), SEO_INDEX=(bool, False), + SENTRY_DSN=(str, ""), + SENTRY_ENVIRONMENT=(str, ""), ) # Read local secrets @@ -286,3 +288,21 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") if not DEBUG: SECURE_HSTS_SECONDS = 86400 # 1 day + +if sentry_dsn := env("SENTRY_DSN"): + import sentry_sdk + from sentry_sdk.integrations.django import DjangoIntegration + from sentry_sdk.integrations.redis import RedisIntegration + from sentry_sdk.integrations.rq import RqIntegration + from sentry_sdk.utils import get_default_release + + sentry_kwargs = { + "dsn": sentry_dsn, + "integrations": [DjangoIntegration(), RqIntegration(), RedisIntegration()], + "release": get_default_release(), + } + + if sentry_environment := env("SENTRY_ENVIRONMENT"): + sentry_kwargs.update({"environment": sentry_environment}) + + sentry_sdk.init(**sentry_kwargs)