4

Uncaught exceptions are not being reported to sentry.

I have ran manage.py raven test and I get the test message in sentry to confirm the communication is working.

My configurations include:

# settings.py

RAVEN_CONFIG = {
    'dsn': '****',
}

SENTRY_CLIENT = 'raven.contrib.django.raven_compat.DjangoClient'

SENTRY_AUTO_LOG_STACKS = True

INSTALLED_APPS += [
    'raven.contrib.django.raven_compat',
]

then

# wsgi.py

from raven.contrib.django.raven_compat.models import client

client.captureException()
Rich Tier
  • 9,021
  • 10
  • 48
  • 71

2 Answers2

4

As shown in the docs, you should call client.captureException() when there is an exception:

try:
    1 / 0
except ZeroDivisionError:
    client.captureException()

In wsgi.py you should do this instead:

from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
from django.core.handlers.wsgi import WSGIHandler

application = Sentry(WSGIHandler()
warvariuc
  • 57,116
  • 41
  • 173
  • 227
0

First thing You need to hardcode your DSN as it contain importante information, then on django i think it's better to work with python logging

RAVEN_CONFIG = {
'dsn': os.environ.get('SENTRY_DSN'),
}

 LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
    'verbose': {
        'format': '%(levelname)s [%(pathname)s:%(lineno)d] - %(message)s'
    },
    'simple': {
        'format': '%(levelname)s %(message)s'
    },
},
'handlers': {
    'sentry': {
        'level': 'ERROR',
        'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
        'tags': {'custom-tag': os.environ.get('SENTRY_TAG')},
    },
    'console': {
        'level': 'ERROR',
        'class': 'logging.StreamHandler',
        'formatter': 'verbose'
    }
},
'loggers': {
    'django': {
        'handlers': ['console', 'sentry'],
        'level': 'ERROR',
    },
    'Your_app {
        'handlers': ['console', 'sentry'],
        'level': 'ERROR',
    },
    'raven': {
        'level': 'ERROR',
        'handlers': ['sentry', 'console'],
        'propagate': False,
    }

}
}

then run python manage.py raven test and share the console message