{ "html": "
\n

Installation

\n

If you haven’t already, start by downloading Raven. The easiest way is\nwith pip:

\n
pip install raven --upgrade\n
\n
\n
\n\n\n
\n

Celery

\n

Celery is a distributed task queue\nsystem for Python built on AMQP principles. For Celery built-in support\nby Raven is provided but it requires some manual configuration.

\n
\n

Installation

\n

If you haven’t already, start by downloading Raven. The easiest way is\nwith pip:

\n
pip install raven --upgrade\n
\n
\n
\n
\n

Setup

\n

To capture errors, you need to register a couple of signals to hijack\nCelery error handling:

\n
from raven import Client\nfrom raven.contrib.celery import register_signal, register_logger_signal\n\nclient = Client('___DSN___')\n\n# register a custom filter to filter out duplicate logs\nregister_logger_signal(client)\n\n# The register_logger_signal function can also take an optional argument\n# `loglevel` which is the level used for the handler created.\n# Defaults to `logging.ERROR`\nregister_logger_signal(client, loglevel=logging.INFO)\n\n# hook into the Celery error handler\nregister_signal(client)\n\n# The register_signal function can also take an optional argument\n# `ignore_expected` which causes exception classes specified in Task.throws\n# to be ignored\nregister_signal(client, ignore_expected=True)\n
\n
\n

A more complex version to encapsulate behavior:

\n
import celery\nimport raven\nfrom raven.contrib.celery import register_signal, register_logger_signal\n\nclass Celery(celery.Celery):\n\n    def on_configure(self):\n        client = raven.Client('___DSN___')\n\n        # register a custom filter to filter out duplicate logs\n        register_logger_signal(client)\n\n        # hook into the Celery error handler\n        register_signal(client)\n\napp = Celery(__name__)\napp.config_from_object('django.conf:settings')\n
\n
\n
\n
\n", "link": "https://docs.getsentry.com/clients/python/integrations/celery/", "id": "python-celery", "name": "Celery" }