8

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")    
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • try adding *exc_info* to info() as provided in docs. Also, check that celery uses the same settings.py. – ilvar Mar 22 '12 at 02:07
  • You only have to use 'raven.contrib.django.celery' in your INSTALLED_APPS if you need looging asynchronously – diegueus9 Mar 22 '12 at 03:00

2 Answers2

10

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,
        },
    },
}
diegueus9
  • 29,351
  • 16
  • 62
  • 74
  • Look the level, maybe you need DEBUG instead of WARNING – diegueus9 Mar 22 '12 at 03:00
  • This still doesn't work unfortunately. I don't understand why the `raven` logger is logging to the `console` handler and not `sentry`. Is this because there is a `root` logger that picks up everything? – Timmy O'Mahony Mar 27 '12 at 14:03
  • In my snippet I'm telling to raven explicit that log to console, the root logger tells by default send logs to sentry, I think the issue has anything with the versions, I test this with celery 2.4.6, django-celery 2.4.2, and rave 1.4.3 but I test it again with the lastest versions and the logs of taks does not appear in sentry – diegueus9 Mar 27 '12 at 19:33
  • So I upgrade sentry to 4.0.17 and raven to 1.75 (celery 2.5.1) and simply adding a celery logger seems to work fine now. Thanks for your help – Timmy O'Mahony May 04 '12 at 13:52
4

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

Community
  • 1
  • 1
Rmatt
  • 1,287
  • 1
  • 16
  • 30