v0.165.0
 1"""OTel-related helpers shared across Plain packages."""
 2
 3
 4def format_exception_type(exc: BaseException) -> str:
 5    """Format an exception's class name per OTel semantic conventions.
 6
 7    Returns the fully-qualified class name (``module.qualname``) for
 8    third-party and user-defined exceptions. Python builtins drop the
 9    ``builtins.`` prefix so common exceptions stay short.
10
11    Used for the ``error.type`` span attribute, which SHOULD match the
12    ``exception.type`` attribute written by ``span.record_exception()``.
13
14    Examples::
15
16        ValueError                      -> "ValueError"
17        django.db.utils.IntegrityError  -> "django.db.utils.IntegrityError"
18        myapp.errors.BillingError       -> "myapp.errors.BillingError"
19    """
20    cls = type(exc)
21    if cls.__module__ == "builtins":
22        return cls.__qualname__
23    return f"{cls.__module__}.{cls.__qualname__}"