2019-04-29 17:16:49 +00:00
|
|
|
"""passbook sentry integration"""
|
2020-10-28 18:00:11 +00:00
|
|
|
from aioredis.errors import ReplyError
|
2020-02-23 18:48:14 +00:00
|
|
|
from billiard.exceptions import WorkerLostError
|
|
|
|
from botocore.client import ClientError
|
2020-09-15 09:29:43 +00:00
|
|
|
from celery.exceptions import CeleryError
|
2020-09-30 13:55:59 +00:00
|
|
|
from channels_redis.core import ChannelFull
|
2020-02-23 18:48:14 +00:00
|
|
|
from django.core.exceptions import DisallowedHost, ValidationError
|
|
|
|
from django.db import InternalError, OperationalError, ProgrammingError
|
|
|
|
from django_redis.exceptions import ConnectionInterrupted
|
2020-09-19 13:25:17 +00:00
|
|
|
from ldap3.core.exceptions import LDAPException
|
2020-09-06 14:51:50 +00:00
|
|
|
from redis.exceptions import ConnectionError as RedisConnectionError
|
2020-10-28 18:00:11 +00:00
|
|
|
from redis.exceptions import RedisError, ResponseError
|
2020-02-23 18:48:14 +00:00
|
|
|
from rest_framework.exceptions import APIException
|
2019-10-01 08:24:10 +00:00
|
|
|
from structlog import get_logger
|
2020-09-30 13:55:59 +00:00
|
|
|
from websockets.exceptions import WebSocketException
|
2019-06-25 16:00:54 +00:00
|
|
|
|
2019-10-04 08:08:53 +00:00
|
|
|
LOGGER = get_logger()
|
2019-04-29 17:16:49 +00:00
|
|
|
|
|
|
|
|
2020-02-20 20:37:14 +00:00
|
|
|
class SentryIgnoredException(Exception):
|
2020-02-24 13:40:12 +00:00
|
|
|
"""Base Class for all errors that are suppressed, and not sent to sentry."""
|
2020-02-20 20:37:14 +00:00
|
|
|
|
|
|
|
|
2019-04-29 17:16:49 +00:00
|
|
|
def before_send(event, hint):
|
|
|
|
"""Check if error is database error, and ignore if so"""
|
2019-06-25 16:00:54 +00:00
|
|
|
ignored_classes = (
|
2020-10-28 18:00:11 +00:00
|
|
|
# Inbuilt types
|
|
|
|
KeyboardInterrupt,
|
|
|
|
ConnectionResetError,
|
|
|
|
OSError,
|
|
|
|
# Django DB Errors
|
2019-04-29 17:16:49 +00:00
|
|
|
OperationalError,
|
2020-02-23 18:48:14 +00:00
|
|
|
InternalError,
|
|
|
|
ProgrammingError,
|
2020-10-28 18:00:11 +00:00
|
|
|
DisallowedHost,
|
|
|
|
ValidationError,
|
|
|
|
# Redis errors
|
|
|
|
RedisConnectionError,
|
2019-04-29 17:16:49 +00:00
|
|
|
ConnectionInterrupted,
|
2020-10-28 18:00:11 +00:00
|
|
|
RedisError,
|
|
|
|
ResponseError,
|
|
|
|
ReplyError,
|
|
|
|
# websocket errors
|
|
|
|
ChannelFull,
|
|
|
|
WebSocketException,
|
|
|
|
# rest_framework error
|
2019-06-25 16:00:54 +00:00
|
|
|
APIException,
|
2020-10-28 18:00:11 +00:00
|
|
|
# celery errors
|
2019-06-25 16:00:54 +00:00
|
|
|
WorkerLostError,
|
2020-10-28 18:00:11 +00:00
|
|
|
CeleryError,
|
|
|
|
# S3 errors
|
2019-12-31 11:51:16 +00:00
|
|
|
ClientError,
|
2020-10-28 18:00:11 +00:00
|
|
|
# custom baseclass
|
2020-02-24 18:14:43 +00:00
|
|
|
SentryIgnoredException,
|
2020-10-28 18:00:11 +00:00
|
|
|
# ldap errors
|
2020-09-19 13:24:52 +00:00
|
|
|
LDAPException,
|
2019-06-25 16:00:54 +00:00
|
|
|
)
|
2019-12-31 11:51:16 +00:00
|
|
|
if "exc_info" in hint:
|
2020-07-07 12:02:20 +00:00
|
|
|
_, exc_value, _ = hint["exc_info"]
|
2020-02-24 18:14:43 +00:00
|
|
|
if isinstance(exc_value, ignored_classes):
|
2019-06-25 16:00:54 +00:00
|
|
|
LOGGER.info("Supressing error %r", exc_value)
|
2019-04-29 17:16:49 +00:00
|
|
|
return None
|
|
|
|
return event
|