Repository: comic/grand-challenge.org

Issue:
Migrate from raven to sentry sdk
Raven is now deprecated, and has been replaced by sentry-sdk: 

https://github.com/getsentry/raven-python
https://github.com/getsentry/sentry-python
https://forum.sentry.io/t/switching-to-sentry-python/4733
https://docs.sentry.io/platforms/python/django/


Discussion:

Resolving patch:
diff --git a/app/config/settings.py b/app/config/settings.py
--- a/app/config/settings.py
+++ b/app/config/settings.py
@@ -1,4 +1,3 @@
-# Django settings for comic project.
 import glob
 import os
 import re
@@ -6,8 +5,10 @@
 from datetime import timedelta
 from distutils.util import strtobool as strtobool_i
 
+import sentry_sdk
 from django.contrib.messages import constants as messages
 from django.core.exceptions import ImproperlyConfigured
+from sentry_sdk.integrations.django import DjangoIntegration
 
 from config.denylist import USERNAME_DENYLIST
 
@@ -17,7 +18,6 @@ def strtobool(val) -> bool:
     return bool(strtobool_i(val))
 
 
-# Default COMIC settings, to be included by settings.py
 DEBUG = strtobool(os.environ.get("DEBUG", "True"))
 
 ADMINS = (
@@ -181,7 +181,6 @@ def strtobool(val) -> bool:
     }
 }
 
-
 ROOT_URLCONF = "config.urls"
 SUBDOMAIN_URL_CONF = "grandchallenge.subdomains.urls"
 DEFAULT_SCHEME = os.environ.get("DEFAULT_SCHEME", "https")
@@ -261,10 +260,10 @@ def strtobool(val) -> bool:
 
 MIDDLEWARE = (
     "django.middleware.security.SecurityMiddleware",  # Keep security at top
-    "whitenoise.middleware.WhiteNoiseMiddleware",  # Keep whitenoise after security and before all else
+    "whitenoise.middleware.WhiteNoiseMiddleware",
+    # Keep whitenoise after security and before all else
     "django.middleware.common.BrokenLinkEmailsMiddleware",
     # Keep BrokenLinkEmailsMiddleware near the top
-    "raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware",
     "django.contrib.sessions.middleware.SessionMiddleware",
     "django.middleware.common.CommonMiddleware",
     "django.middleware.csrf.CsrfViewMiddleware",
@@ -279,7 +278,6 @@ def strtobool(val) -> bool:
     "grandchallenge.subdomains.middleware.subdomain_urlconf_middleware",
 )
 
-
 # Python dotted path to the WSGI application used by Django's runserver.
 WSGI_APPLICATION = "config.wsgi.application"
 
@@ -298,7 +296,6 @@ def strtobool(val) -> bool:
 ]
 
 THIRD_PARTY_APPS = [
-    "raven.contrib.django.raven_compat",  # error logging
     "django_celery_results",  # database results backend
     "django_celery_beat",  # periodic tasks
     "djcelery_email",  # asynchronous emails
@@ -492,32 +489,11 @@ def strtobool(val) -> bool:
 
 # A sample logging configuration. More info in configuration can be found at
 # https://docs.djangoproject.com/en/dev/topics/logging/ .
-# This configuration writes WARNING and worse errors to an error log file, and
-# sends an email to all admins. It also writes INFO logmessages and worse to a
-# regular log file.
-LOG_FILEPATH = "/tmp/django.log"
-LOG_FILEPATH_ERROR = "/tmp/django_error.log"
 LOGGING = {
     "version": 1,
-    "disable_existing_loggers": True,
-    "root": {"level": "WARNING", "handlers": ["sentry"]},
-    "formatters": {
-        "verbose": {
-            "format": "%(levelname)s %(asctime)s %(module)s "
-            "%(process)d %(thread)d %(message)s"
-        }
-    },
+    "disable_existing_loggers": False,
     "handlers": {
-        "sentry": {
-            "level": "ERROR",
-            # To capture more than ERROR, change to WARNING, INFO, etc.
-            "class": "raven.contrib.django.raven_compat.handlers.SentryHandler",
-        },
-        "console": {
-            "level": "DEBUG",
-            "class": "logging.StreamHandler",
-            "formatter": "verbose",
-        },
+        "console": {"level": "DEBUG", "class": "logging.StreamHandler"}
     },
     "loggers": {
         "grandchallenge": {
@@ -530,16 +506,6 @@ def strtobool(val) -> bool:
             "handlers": ["console"],
             "propagate": False,
         },
-        "raven": {
-            "level": "DEBUG",
-            "handlers": ["console"],
-            "propagate": False,
-        },
-        "sentry.errors": {
-            "level": "DEBUG",
-            "handlers": ["console"],
-            "propagate": False,
-        },
         "werkzeug": {
             "handlers": ["console"],
             "level": "DEBUG",
@@ -548,7 +514,10 @@ def strtobool(val) -> bool:
     },
 }
 
-RAVEN_CONFIG = {"dsn": os.environ.get("DJANGO_SENTRY_DSN", "")}
+sentry_sdk.init(
+    dsn=os.environ.get("DJANGO_SENTRY_DSN", ""),
+    integrations=[DjangoIntegration()],
+)
 
 REST_FRAMEWORK = {
     "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAdminUser",),


Test patch: