Celery tasks uncaught exceptions not being sent to Sentry Celery tasks uncaught exceptions not being sent to Sentry django django

Celery tasks uncaught exceptions not being sent to Sentry


As described by DRC in the comment up there, we finally got to the solution using this approach:https://docs.getsentry.com/hosted/clients/python/integrations/celery/

Basically doing this:

import celeryclass Celery(celery.Celery):    def on_configure(self):        if hasattr(settings, 'RAVEN_CONFIG') and settings.RAVEN_CONFIG['dsn']:            import raven            from raven.contrib.celery import (register_signal,                                              register_logger_signal)            client = raven.Client(settings.RAVEN_CONFIG['dsn'])            register_logger_signal(client)            register_signal(client)app = Celery('myapp')app.config_from_object('django.conf:settings')app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

Thanks for your time.


The chosen answer is correct as the question states raven is being used.However raven has been deprecated in favour of the sentry SDK.

To configure django and celery with the sentry SDK:

First add sentry-sdk to your requirements file.

Then, in your django setttings file:

import sentry_sdkfrom sentry_sdk.integrations.django import DjangoIntegrationfrom sentry_sdk.integrations.celery import CeleryIntegrationsentry_sdk.init(    dsn="your_sentry_DSN",    integrations=[DjangoIntegration(), CeleryIntegration()],    send_default_pii=True)

Sources: