How to filter out errors which are handled by try catch

As per Sentry docs even if the user handles the exception it will be logged in sentry with handled flag as yes.

But how to avoid the logging of handled exceptions in sentry ??

I am using sentry-sdk (0.14.1) and below integrations:
DjangoIntegration
CeleryIntegration
RedisIntegration

hey @thiyaguby you could use the beforeSend callback.

@marandaneto Thanks for the suggestion.

How do I get the handled flag inside that beforeSend method… ?? I tried that but couldn’t find that flag in the arguments…

cc @untitaker

No news on this? I have the exact same problem. Requests are made, with a ton a catches (Exception, requests.ConnectionError, requests.HTTPError, requests.RequestException, NewConnectionError, MaxRetryError) and with a filter:

def before_send(event, hint):
    if 'exc_info' in hint:
        exc_type, exc_value, tb = hint['exc_info']
        if isinstance(exc_value, SSLError):
            event['fingerprint'] = ['ssl-error']
        if isinstance(exc_value, NewConnectionError):
            event['fingerprint'] = ['new-connection-error']
        if isinstance(exc_value, MaxRetryError):
            event['fingerprint'] = ['max-retry-error']
    return event

And still, I receive the emails and get (un-grouped) entries on Sentry. I can’t get it working. Any idea?

To be precise, this is the message I get on Sentry:

HTTPSConnectionPool(host='www.swift.psu.edu', port=443): Max retries exceeded with url: /operations/obsSchedule.php?d=2020-08-13&a=1 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f53166db730>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

I thought that witch catches and a before_send method, I could filter them out, or at least group them. Which one I should catch ?

Can you link two issues that are supposed to be grouped together?

Why do you mean by “link”? I often merge issues, but that’s it. They keep coming separated.

hi, have somebody solved it?

i got 50k handled exceptions sent to sentry daily (and under 10 unhandled), there is absolutely no need in those handled exceptions in sentry.
I guess if its made like that just to increase invoice totals ? :upside_down_face:

probably will get fixed with such beforeSend, will test in next billing period

def sentry_before_send(event, hint):
        exceptions = event['exception']
        if exceptions:
            exc = exceptions[-1]
            mechanism = exc.get('mechanism')
            if mechanism:
                if mechanism.get('handled'):
                    return None

        return event

It works :slight_smile: