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")
Celery makes it easier to implement the task queues for many workers in a Django application.
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.
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).
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,
},
},
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With