Celery tasks uncaught exceptions not being sent to Sentry

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_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration

sentry_sdk.init(
    dsn="your_sentry_DSN",
    integrations=[DjangoIntegration(), CeleryIntegration()],
    send_default_pii=True
)

Sources:

  • Get your DSN: https://docs.sentry.io/clients/java/config/#setting-the-dsn
  • Sentry Django integration: https://docs.sentry.io/platforms/python/django/
  • Sentry Celery integration: https://docs.sentry.io/platforms/python/celery/

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 celery

class 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.