Support SENTRY_IGNORE_EXCEPTIONS in Django as a solution for the removed skip_sentry behavior
This commit is contained in:
parent
afbde25e28
commit
fcc34abbe0
2
CHANGES
2
CHANGES
|
@ -28,7 +28,7 @@ Additionally, the following has changed:
|
|||
* Django 1.5 should now be supported (experimental).
|
||||
* Gevent 1.0 should now be supported (experimental).
|
||||
* Python 2.5 is no longer supported.
|
||||
* [Django] The ``skip_sentry`` attribute is no longer supported.
|
||||
* [Django] The ``skip_sentry`` attribute is no longer supported. A new option config option has replaced this: ``SENTRY_IGNORE_EXCEPTIONS``.
|
||||
|
||||
Version 2.0.0
|
||||
-------------
|
||||
|
|
|
@ -11,8 +11,8 @@ Acts as an implicit hook for Django installs.
|
|||
from __future__ import absolute_import
|
||||
|
||||
from hashlib import md5
|
||||
import sys
|
||||
import logging
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from django.conf import settings as django_settings
|
||||
|
@ -100,6 +100,12 @@ class ProxyClient(object):
|
|||
client = ProxyClient()
|
||||
|
||||
|
||||
def get_option(x, d=None):
|
||||
options = getattr(django_settings, 'RAVEN_CONFIG', {})
|
||||
|
||||
return getattr(django_settings, 'SENTRY_%s' % x, options.get(x, d))
|
||||
|
||||
|
||||
def get_client(client=None):
|
||||
global _client
|
||||
|
||||
|
@ -108,10 +114,9 @@ def get_client(client=None):
|
|||
client = getattr(django_settings, 'SENTRY_CLIENT', 'raven.contrib.django.DjangoClient')
|
||||
|
||||
if _client[0] != client:
|
||||
ga = lambda x, d=None: getattr(django_settings, 'SENTRY_%s' % x, d)
|
||||
|
||||
module, class_name = client.rsplit('.', 1)
|
||||
|
||||
ga = lambda x, d=None: getattr(django_settings, 'SENTRY_%s' % x, d)
|
||||
options = getattr(django_settings, 'RAVEN_CONFIG', {})
|
||||
options.setdefault('servers', ga('SERVERS'))
|
||||
options.setdefault('include_paths', ga('INCLUDE_PATHS', []))
|
||||
|
@ -162,22 +167,22 @@ def sentry_exception_handler(request=None, **kwargs):
|
|||
@transaction.commit_on_success
|
||||
def actually_do_stuff(request=None, **kwargs):
|
||||
exc_info = sys.exc_info()
|
||||
try:
|
||||
# HACK: this ensures Sentry can report its own errors
|
||||
if 'sentry' in django_settings.INSTALLED_APPS and transaction.is_dirty():
|
||||
transaction.rollback()
|
||||
|
||||
if exc_info[0].__name__ in get_option('IGNORE_EXCEPTIONS', tuple()):
|
||||
logger.info('Not capturing exception due to filters: %s', exc_info[0], exc_info=exc_info)
|
||||
return
|
||||
|
||||
# HACK: this ensures Sentry can report its own errors
|
||||
if 'sentry' in django_settings.INSTALLED_APPS and transaction.is_dirty():
|
||||
transaction.rollback()
|
||||
|
||||
try:
|
||||
client.captureException(exc_info=exc_info, request=request)
|
||||
except Exception, exc:
|
||||
try:
|
||||
logger.exception(u'Unable to process log entry: %s' % (exc,))
|
||||
except Exception, exc:
|
||||
warnings.warn(u'Unable to process log entry: %s' % (exc,))
|
||||
finally:
|
||||
try:
|
||||
del exc_info
|
||||
except Exception, e:
|
||||
logger.exception(e)
|
||||
|
||||
return actually_do_stuff(request, **kwargs)
|
||||
|
||||
|
|
|
@ -656,6 +656,17 @@ class SentryExceptionHandlerTest(TestCase):
|
|||
@mock.patch('sys.exc_info')
|
||||
def test_does_capture_exception(self, exc_info, captureException):
|
||||
exc_info.return_value = self.exc_info
|
||||
sentry_exception_handler(self.request)
|
||||
sentry_exception_handler(request=self.request)
|
||||
|
||||
captureException.assert_called_once_with(exc_info=self.exc_info, request=self.request)
|
||||
|
||||
@mock.patch.object(TempStoreClient, 'captureException')
|
||||
@mock.patch('sys.exc_info')
|
||||
@mock.patch('raven.contrib.django.models.get_option')
|
||||
def test_does_exclude_filtered_types(self, get_option, exc_info, captureException):
|
||||
exc_info.return_value = self.exc_info
|
||||
get_option.return_value = ['ValueError']
|
||||
|
||||
sentry_exception_handler(request=self.request)
|
||||
|
||||
assert not captureException.called
|
||||
|
|
Loading…
Reference in New Issue