{ "html": "
If you haven’t already, start by downloading Raven. The easiest way is\nwith pip:
\npip install raven --upgrade\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.
\nIf you haven’t already, start by downloading Raven. The easiest way is\nwith pip:
\npip install raven --upgrade\n
To capture errors, you need to register a couple of signals to hijack\nCelery error handling:
\nfrom 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
A more complex version to encapsulate behavior:
\nimport 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