getsentry / raven-python

Raven is the legacy Python client for Sentry (getsentry.com) — replaced by sentry-python
https://sentry.io
BSD 3-Clause "New" or "Revised" License
1.68k stars 657 forks source link

Exception being send to Sentry even when added to ignore_exception #869

Open canassa opened 8 years ago

canassa commented 8 years ago

Hello,

I have a Django project using raven 5.27.1 and I setting the the ignore_exception like so:

RAVEN_CONFIG = {
    ...
    'ignore_exceptions': [myproject.base.exceptions.BackOffException'],
    ...
}

I also have a celery task that raises that exception:

@shared_task(throws=(BackOffException,))
def my_useful_task():
     raise BackOffException

My problem is that raven is not respecting my ignore_exception config and sending the exception to Sentry anyway. The problem seems to be that the should_capture is being executed twice, I added the following to log to it:

    def should_capture(self, exc_info):
        exc_type = exc_info[0]
        exc_name = '%s.%s' % (exc_type.__module__, exc_type.__name__)
        exclusions = self.ignore_exceptions
        self.logger.error('hello {} {}'.format(exc_name, exclusions))

And these are logs that I am seeing:

hello myproject.base.exceptions.BackOffException set()

hello myproject.base.exceptions.BackOffException {'myproject.base.exceptions.BackOffException'}

Not capturing exception due to filters: <class 'myproject.base.exceptions.BackOffException'>

Traceback (most recent call last):
  File "/code/virtualenv/CURRENT/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/code/virtualenv/CURRENT/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/code/scp/python/myproject/tasks.py", line 98, in my_useful_task
    raise BackOffException
myproject.base.exceptions.BackOffException
pathname=/code/virtualenv/CURRENT/lib/python3.5/site-packages/celery/utils/log.py lineno=282 Task myproject.my_useful_task[145d2141-8fbc-4c9e-bcad-4ce8c3d9b7d9] raised unexpected: BackOffException()
Traceback (most recent call last):
  File "/code/virtualenv/CURRENT/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/code/virtualenv/CURRENT/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/code/scp/python/myproject/tasks.py", line 98, in my_useful_task
    raise BackOffException
myproject.base.exceptions.BackOffException

As you can see, should_capture was called twice, the first time the exclusion list was an empty set. I think this is causing the error to be sent to Sentry anyway

mitsuhiko commented 8 years ago

Can you print out object.__repr__(self) in that should_capture method and copy paste the output here?

canassa commented 8 years ago

@mitsuhiko

Sure, I added this line to it:

def should_capture(self, exc_info):
    self.logger.error('arcoiro {}'.format(object.__repr__(self)))

And here is the output:

23/Sep/2016:10:03:00 +0200 ERROR arcoiro <raven.base.Client object at 0x7f470c30ec88>
23/Sep/2016:10:03:00 +0200 ERROR arcoiro <myproject.infra.utils.RavenClient object at 0x7f4701659748>

I didn't mention this before but I am using the SENTRY_CLIENT configuration to overwrite the raven client, I have this in my Django settings:

SENTRY_CLIENT = 'myproject.infra.utils.RavenClient'

And this is my custom client (in case it matters):

class RavenClient(DjangoClient):
    """
    Adds the logging request_uuid identifier to the exception sent to
    Sentry, it enables finding all logs related to a given exception.
    """

    def build_msg(self, *args, **kwargs):
        data = super().build_msg(*args, **kwargs)

        log_data = getattr(threadlocal, 'log_data', None)

        if log_data and 'request_uuid' in log_data:
            data['extra']['request_uuid'] = log_data['request_uuid']

        return data
gslusarek-cic commented 7 years ago

any update here?