Skip to content

popoto._error_reporting

popoto._error_reporting

Opt-in error reporting for Popoto via an isolated Sentry client.

This module provides a way for Popoto users to automatically report library-specific errors back to the Popoto maintainers. It is entirely opt-in: nothing runs unless enable_error_reporting() is called, and the feature degrades silently if sentry-sdk is not installed or any internal error occurs.

The Sentry client is fully isolated from the application's own Sentry configuration -- it never calls sentry_sdk.init() and never touches the global scope.

enable_error_reporting(dsn=None)

Enable opt-in error reporting to the Popoto maintainers.

When enabled, exceptions originating in Popoto code are reported to a Sentry project maintained by the Popoto authors. This helps identify and fix bugs that users encounter in the wild.

This is entirely opt-in. You must call this function explicitly for any reporting to occur. If sentry-sdk is not installed, this function silently does nothing.

The reporter uses an isolated Sentry client that does not interfere with your application's own sentry_sdk.init() or global Sentry configuration.

Parameters:

Name Type Description Default
dsn Optional[str]

Optional Sentry DSN override. By default, errors are reported to the Popoto maintainers' Sentry project. Set POPOTO_SENTRY_DSN env var or pass a DSN here to redirect reports to your own project instead.

None

Example::

import popoto

popoto.enable_error_reporting()
Source code in src/popoto/_error_reporting.py
def enable_error_reporting(dsn: Optional[str] = None) -> None:
    """Enable opt-in error reporting to the Popoto maintainers.

    When enabled, exceptions originating in Popoto code are reported to
    a Sentry project maintained by the Popoto authors. This helps
    identify and fix bugs that users encounter in the wild.

    **This is entirely opt-in.** You must call this function explicitly
    for any reporting to occur. If ``sentry-sdk`` is not installed, this
    function silently does nothing.

    The reporter uses an isolated Sentry client that does **not**
    interfere with your application's own ``sentry_sdk.init()`` or
    global Sentry configuration.

    Args:
        dsn: Optional Sentry DSN override. By default, errors are
            reported to the Popoto maintainers' Sentry project. Set
            ``POPOTO_SENTRY_DSN`` env var or pass a DSN here to
            redirect reports to your own project instead.

    Example::

        import popoto

        popoto.enable_error_reporting()
    """
    try:
        _do_enable(dsn)
    except Exception:
        # Never let reporter setup interfere with the library.
        pass

capture_exception(exc=None)

Capture an exception and send it to the Popoto Sentry project.

This is a no-op if error reporting has not been enabled or if any internal error occurs.

Source code in src/popoto/_error_reporting.py
def capture_exception(exc: Optional[BaseException] = None) -> None:
    """Capture an exception and send it to the Popoto Sentry project.

    This is a no-op if error reporting has not been enabled or if any
    internal error occurs.
    """
    try:
        if not _enabled or _client is None:
            return
        from sentry_sdk.utils import event_from_exception

        if exc is not None:
            exc_info = (type(exc), exc, exc.__traceback__)
        else:
            import sys

            exc_info = sys.exc_info()

        event, hint = event_from_exception(
            exc_info, client_options=_client.options
        )
        _client.capture_event(event, hint=hint)
    except Exception:
        pass