Ignore_exceptions in Sentry SDK(python)?

So i wonder how to ignore a list of exceptions to not be sent to Sentry when migrating from Raven to Sentry SDK?

I tried returning None in before_send, but this doesn’t work, issues still created in Sentry.

def before_send_sentry_handler(event, hint):
    if "exc_info" in hint:
        exc_type, exc_value, tb = hint["exc_info"]
        if isinstance(exc_value, (NotFound, MethodNotAllowed)):
            # To discard Sentry event return None
            return None

    return event

Your before_send should definetly work. Are you passing it to init() as well?

Yes, i debugged it, it enters the handler and returns None. here is the init:

sentry_sdk.init(
    dsn=config.SENTRY_DSN,
    environment=config.SENTRY_ENVIRONMENT,
    release=config.DEPLOY_DATA.get("revision"),
    before_send=before_send_sentry_handler,
    integrations=[CeleryIntegration(), FlaskIntegration()],
)

Never mind, i forgot to remove the init of the old raven client… sorry for stupid issue.

1 Like