2019-04-29 19:16:49 +02:00
|
|
|
"""passbook sentry integration"""
|
2020-02-23 19:48:14 +01: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 10:24:10 +02:00
|
|
|
from structlog import get_logger
|
2019-06-25 18:00:54 +02:00
|
|
|
|
2019-10-04 10:08:53 +02:00
|
|
|
LOGGER = get_logger()
|
2019-04-29 19:16:49 +02:00
|
|
|
|
|
|
|
|
2020-02-20 21:37:14 +01:00
|
|
|
class SentryIgnoredException(Exception):
|
|
|
|
"""Base Class for all errors that are supressed, and not sent to sentry."""
|
|
|
|
|
|
|
|
|
2019-04-29 19:16:49 +02:00
|
|
|
def before_send(event, hint):
|
|
|
|
"""Check if error is database error, and ignore if so"""
|
2019-06-25 18:00:54 +02:00
|
|
|
ignored_classes = (
|
2019-04-29 19:16:49 +02:00
|
|
|
OperationalError,
|
2020-02-23 19:48:14 +01:00
|
|
|
InternalError,
|
|
|
|
ProgrammingError,
|
2019-04-29 19:16:49 +02:00
|
|
|
ConnectionInterrupted,
|
2019-06-25 18:00:54 +02:00
|
|
|
APIException,
|
|
|
|
ConnectionResetError,
|
|
|
|
WorkerLostError,
|
|
|
|
DisallowedHost,
|
|
|
|
ConnectionResetError,
|
2019-11-02 16:27:28 +00:00
|
|
|
KeyboardInterrupt,
|
2019-12-31 12:51:16 +01:00
|
|
|
ClientError,
|
2020-02-19 10:54:29 +01:00
|
|
|
ValidationError,
|
2020-02-19 17:13:44 +01:00
|
|
|
OSError,
|
|
|
|
RedisError,
|
2020-02-20 21:37:14 +01:00
|
|
|
SentryIgnoredException,
|
2019-06-25 18:00:54 +02:00
|
|
|
)
|
2019-12-31 12:51:16 +01:00
|
|
|
if "exc_info" in hint:
|
|
|
|
_exc_type, exc_value, _ = hint["exc_info"]
|
2019-04-29 19:16:49 +02:00
|
|
|
if isinstance(exc_value, ignored_classes):
|
2019-06-25 18:00:54 +02:00
|
|
|
LOGGER.info("Supressing error %r", exc_value)
|
2019-04-29 19:16:49 +02:00
|
|
|
return None
|
|
|
|
return event
|