authentik.lib.tracing.exceptions

 1from asyncio.exceptions import CancelledError
 2from sys import modules
 3
 4from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation, ValidationError
 5from django.db import DatabaseError, InternalError, OperationalError, ProgrammingError
 6from django.http.response import Http404
 7from dramatiq.errors import Retry
 8from h11 import LocalProtocolError
 9from psycopg.errors import Error
10from rest_framework.exceptions import APIException
11
12
13class TracingIgnoredException(Exception):
14    """Base Class for all errors that are suppressed, and not recorded as span errors."""
15
16
17ignored_classes = (
18    # Inbuilt types
19    KeyboardInterrupt,
20    ConnectionResetError,
21    OSError,
22    PermissionError,
23    # Django Errors
24    Error,
25    ImproperlyConfigured,
26    DatabaseError,
27    OperationalError,
28    InternalError,
29    ProgrammingError,
30    SuspiciousOperation,
31    ValidationError,
32    LocalProtocolError,
33    # rest_framework error
34    APIException,
35    # dramatiq errors
36    Retry,
37    # custom baseclass
38    TracingIgnoredException,
39    # End-user errors
40    Http404,
41    # AsyncIO
42    CancelledError,
43)
44
45
46# Exceptions of optional, heavy libraries. Checked only once the library has been imported,
47# as an exception can't come from a module that was never loaded.
48lazy_ignored_classes = (
49    ("websockets.exceptions", "WebSocketException"),
50    ("ldap3.core.exceptions", "LDAPException"),
51    ("docker.errors", "DockerException"),
52)
53
54
55def should_ignore_exception(exc: Exception) -> bool:
56    """Check if an exception should be dropped"""
57    if isinstance(exc, ignored_classes):
58        return True
59    return any(
60        module in modules and isinstance(exc, getattr(modules[module], name))
61        for module, name in lazy_ignored_classes
62    )
class TracingIgnoredException(builtins.Exception):
14class TracingIgnoredException(Exception):
15    """Base Class for all errors that are suppressed, and not recorded as span errors."""

Base Class for all errors that are suppressed, and not recorded as span errors.

ignored_classes = (<class 'KeyboardInterrupt'>, <class 'ConnectionResetError'>, <class 'OSError'>, <class 'PermissionError'>, <class 'psycopg.Error'>, <class 'django.core.exceptions.ImproperlyConfigured'>, <class 'django.db.utils.DatabaseError'>, <class 'django.db.utils.OperationalError'>, <class 'django.db.utils.InternalError'>, <class 'django.db.utils.ProgrammingError'>, <class 'django.core.exceptions.SuspiciousOperation'>, <class 'django.core.exceptions.ValidationError'>, <class 'h11._util.LocalProtocolError'>, <class 'rest_framework.exceptions.APIException'>, <class 'dramatiq.errors.Retry'>, <class 'TracingIgnoredException'>, <class 'django.http.response.Http404'>, <class 'asyncio.exceptions.CancelledError'>)
lazy_ignored_classes = (('websockets.exceptions', 'WebSocketException'), ('ldap3.core.exceptions', 'LDAPException'), ('docker.errors', 'DockerException'))
def should_ignore_exception(exc: Exception) -> bool:
56def should_ignore_exception(exc: Exception) -> bool:
57    """Check if an exception should be dropped"""
58    if isinstance(exc, ignored_classes):
59        return True
60    return any(
61        module in modules and isinstance(exc, getattr(modules[module], name))
62        for module, name in lazy_ignored_classes
63    )

Check if an exception should be dropped