question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document how to use Raven in a Celery worker

See original GitHub issue

There’s no documentation of how to configure Raven in a Celery worker.

Hints of such documentation were removed in commit 6c5afbf. That commit message says “Remove raven.contrib.celery.CeleryClient” but it does other odd unexplained stuff:

  • adds a CeleryClient in raven.contrib.django.celery
  • removes documentation showing how to use register_signal, but doesn’t remove that function (and I guess it is still the intended way to capture Celery task failures…?)
  • removes a class CeleryMixin but adds a docstring referencing it, showing creation of a CeleryClient class like the one being removed.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
gtaylorcommented, Oct 14, 2014

For the sake of being helpful, I’ll point out that as of Celery 3.1, the Django integration looks like this:

http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html

They suggest a celery.py module, which seems like the perfect place for this. Here’s what we have right now, which could be totally off:

from __future__ import absolute_import

import os

from celery import Celery
from raven import Client
from raven.contrib.celery import register_signal

from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pathwright.settings')

app = Celery('pathwright')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

if hasattr(settings, 'RAVEN_CONFIG'):
    # Celery signal registration
    client = Client(dsn=settings.RAVEN_CONFIG['dsn'])
    register_signal(client)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

I hope this helps someone!

2reactions
umazalakaincommented, Dec 15, 2014

I tried this last config and, although my celery worker was outputting that errors were being send to sentry, nothing arrived on the sentry side.

Then I set the CELERYD_HIJACK_ROOT_LOGGER = False and 'disable_existing_loggers': True, in the logging configuration and all the messages arrived, but they arrived duplicated. So I deactivated the registration of raven for failed celery tasks thus, in the end, only tweaking the mentioned two settings, and everything seams to be logged fine.

Of course, the problem of this approach is that you take logging from the hands of celery back to yours but, as far as I see, this shouldn’t be any problem right?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Celery — Raven 5.32.0 documentation
Celery is a distributed task queue system for Python built on AMQP principles. For Celery built-in support by Raven is provided but it...
Read more >
Using raven with celery in django - sentry - Stack Overflow
The celery client in raven uses a routing key on the task: class CeleryMixin(object): def ... http://docs.celeryproject.org/en/latest/userguide/routing.html.
Read more >
[Answered]-sentry, raven and django celery-django
I have set up a standalone server configured a django application to log using django 1.3's logging dictionary conf as per the raven...
Read more >
Workers Guide — Celery 5.2.7 documentation
You can get a list of queues that a worker consumes from by using the active_queues control command: $ celery -A proj inspect...
Read more >
Celery - Sentry Documentation
The Celery integration adds support for the Celery Task Queue System . ... Additionally, the Sentry Python SDK will set the transaction on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found