diff --git a/passbook/core/celery.py b/passbook/core/celery.py index edf1c13a4..300b67434 100644 --- a/passbook/core/celery.py +++ b/passbook/core/celery.py @@ -5,9 +5,8 @@ import os import celery from django.conf import settings - -# from raven import Client -# from raven.contrib.celery import register_logger_signal, register_signal +from raven import Client +from raven.contrib.celery import register_logger_signal, register_signal # set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passbook.core.settings") @@ -18,16 +17,17 @@ LOGGER = logging.getLogger(__name__) class Celery(celery.Celery): """Custom Celery class with Raven configured""" - # def on_configure(self): - # """Update raven client""" - # try: - # client = Client(settings.RAVEN_CONFIG.get('dsn')) - # # register a custom filter to filter out duplicate logs - # register_logger_signal(client) - # # hook into the Celery error handler - # register_signal(client) - # except RecursionError: # This error happens when pdoc is running - # pass + # pylint: disable=method-hidden + def on_configure(self): + """Update raven client""" + try: + client = Client(settings.RAVEN_CONFIG.get('dsn')) + # register a custom filter to filter out duplicate logs + register_logger_signal(client) + # hook into the Celery error handler + register_signal(client) + except RecursionError: # This error happens when pdoc is running + pass # pylint: disable=unused-argument diff --git a/passbook/core/settings.py b/passbook/core/settings.py index 9f42352d6..bed4985c7 100644 --- a/passbook/core/settings.py +++ b/passbook/core/settings.py @@ -62,6 +62,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'rest_framework', 'drf_yasg', + 'raven.contrib.django.raven_compat', 'passbook.core.apps.PassbookCoreConfig', 'passbook.admin.apps.PassbookAdminConfig', 'passbook.api.apps.PassbookAPIConfig', @@ -104,6 +105,7 @@ MIDDLEWARE = [ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', ] ROOT_URLCONF = 'passbook.core.urls' @@ -184,6 +186,14 @@ CELERY_TASK_DEFAULT_QUEUE = 'passbook' CELERY_BROKER_URL = 'redis://%s' % CONFIG.get('redis') CELERY_RESULT_BACKEND = 'redis://%s' % CONFIG.get('redis') +# Raven settings +RAVEN_CONFIG = { + 'dsn': ('https://55b5dd780bc14f4c96bba69b7a9abbcc:449af483bd0745' + '0d83be640d834e5458@sentry.services.beryju.org/8'), + 'release': VERSION, + 'environment': 'dev' if DEBUG else 'production', +} + # CherryPY settings with CONFIG.cd('web'): CHERRYPY_SERVER = { diff --git a/passbook/core/wsgi.py b/passbook/core/wsgi.py index 8cfa77c8e..a8fc46c23 100644 --- a/passbook/core/wsgi.py +++ b/passbook/core/wsgi.py @@ -10,7 +10,8 @@ https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ import os from django.core.wsgi import get_wsgi_application +from raven.contrib.django.raven_compat.middleware.wsgi import Sentry os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'passbook.settings') -application = get_wsgi_application() +application = Sentry(get_wsgi_application())