Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sentry, raven and django celery

Now that django-sentry has become a standalone server (and is fantastic) I'm trying to port my apps over to use it.

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 docs. I can't seem to get any celery tasks to log to the sentry server (they do get printed out to the console though).

I'm not really sure what I should be doing? I have included raven.contrib.django.celery in my `INSTALLED_APPS'.

Uncaught exceptions are being sent to sentry, as are custom logging message via:

import logging
logger = logging.getLogger(__name__)
...
logger.info("Logged Message")    
like image 905
Timmy O'Mahony Avatar asked Mar 21 '12 17:03

Timmy O'Mahony


People also ask

Why Celery is used in Django?

Celery makes it easier to implement the task queues for many workers in a Django application.

Can I use Celery without Django?

Yes you can. Celery is a generic asynchronous task queue. In place of "django_project" you would point to your module. See http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#application for an example.

What is Celery Redis in Django?

Redis is the datastore and message broker between Celery and Django. In other words, Django and Celery use Redis to communicate with each other (instead of a SQL database). Redis can also be used as a cache as well. An alternative for Django & Celery is RabbitMQ (not covered here).


2 Answers

You need to add this:

'celery': {
        'level': 'WARNING',
        'handlers': ['sentry'],
        'propagate': False,
    },

To your loggers in the variable LOGGING in your settings.

something like:

# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'root': {
        'level': 'WARNING',
        'handlers': ['sentry'],
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %    (message)s'
        },
    },
    'handlers': {
        'sentry': {
            'level': 'DEBUG',
            'class': 'raven.contrib.django.handlers.SentryHandler',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'django.db.backends': {
            'level': 'ERROR',
            'handlers': ['console'],
            'propagate': False,
        },
        'raven': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'sentry.errors': {
            'level': 'DEBUG',
            'handlers': ['console'],
            'propagate': False,
        },
        'celery': {
            'level': 'WARNING',
            'handlers': ['sentry'],
            'propagate': False,
        },
    },
}
like image 54
diegueus9 Avatar answered Nov 01 '22 01:11

diegueus9


Since Raven 5+, you may need to add a setting to your Django project, like described in Sentry logging in Django/Celery stopped working

CELERYD_HIJACK_ROOT_LOGGER = False

like image 4
Rmatt Avatar answered Nov 01 '22 02:11

Rmatt