This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/lib/sentry.py

43 lines
1.3 KiB
Python
Raw Normal View History

"""passbook sentry integration"""
2020-02-23 18:48:14 +00:00
from billiard.exceptions import WorkerLostError
from botocore.client import ClientError
from django.core.exceptions import DisallowedHost, ValidationError
from django.db import InternalError, OperationalError, ProgrammingError
from django_redis.exceptions import ConnectionInterrupted
from redis.exceptions import RedisError
from rest_framework.exceptions import APIException
2019-10-01 08:24:10 +00:00
from structlog import get_logger
LOGGER = get_logger()
class SentryIgnoredException(Exception):
"""Base Class for all errors that are supressed, and not sent to sentry."""
def before_send(event, hint):
"""Check if error is database error, and ignore if so"""
ignored_classes = (
OperationalError,
2020-02-23 18:48:14 +00:00
InternalError,
ProgrammingError,
ConnectionInterrupted,
APIException,
ConnectionResetError,
WorkerLostError,
DisallowedHost,
ConnectionResetError,
KeyboardInterrupt,
2019-12-31 11:51:16 +00:00
ClientError,
ValidationError,
2020-02-19 16:13:44 +00:00
OSError,
RedisError,
SentryIgnoredException,
)
2019-12-31 11:51:16 +00:00
if "exc_info" in hint:
_exc_type, exc_value, _ = hint["exc_info"]
if isinstance(exc_value, ignored_classes):
LOGGER.info("Supressing error %r", exc_value)
return None
return event