diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aaf896d74..5bb074231 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,9 @@ This document describes changes between each past release. 16.0.1 (unreleased) ------------------- -- Nothing changed yet. +**New features** + +- Send logging warnings to Sentry, with logging debugs as breadcrumbs. Configure levels with ``kinto.sentry_breadcrumbs_min_level`` and ``kinto.sentry_events_min_level`` settings. 16.0.0 (2023-05-30) diff --git a/docs/configuration/settings.rst b/docs/configuration/settings.rst index b80ff07ae..aafd5feaa 100644 --- a/docs/configuration/settings.rst +++ b/docs/configuration/settings.rst @@ -409,6 +409,10 @@ Sentry reporting can be enabled via the following settings: kinto.sentry_dsn = https://userid@o1.ingest.sentry.io/1 kinto.sentry_env = stage + # Integrate logging with Sentry. + # kinto.sentry_breadcrumbs_min_level = 10 # DEBUG + # kinto.sentry_events_min_level = 30 # WARNING + Or the equivalent environment variables: :: diff --git a/kinto/core/__init__.py b/kinto/core/__init__.py index 173e55004..091bf6bfa 100644 --- a/kinto/core/__init__.py +++ b/kinto/core/__init__.py @@ -89,6 +89,8 @@ "settings_prefix": "", "sentry_dsn": None, "sentry_env": None, + "sentry_breadcrumbs_min_level": logging.DEBUG, + "sentry_events_min_level": logging.WARNING, "statsd_backend": "kinto.core.statsd", "statsd_prefix": "kinto.core", "statsd_url": None, diff --git a/kinto/core/initialization.py b/kinto/core/initialization.py index 0e94420ad..356fca65a 100644 --- a/kinto/core/initialization.py +++ b/kinto/core/initialization.py @@ -29,6 +29,7 @@ ProfilerMiddleware = False try: import sentry_sdk + from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.pyramid import PyramidIntegration from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration except ImportError: # pragma: no cover @@ -284,11 +285,19 @@ def setup_sentry(config): if env: env_options["environment"] = env + breadcrumbs_level = settings["sentry_breadcrumbs_min_level"] + events_level = settings["sentry_events_min_level"] sentry_sdk.init( dsn, integrations=[ PyramidIntegration(), SqlalchemyIntegration(), + LoggingIntegration( + # Logs to be captured as breadcrumbs (debug and above by default) + level=breadcrumbs_level, + # Logs to be catpured as events (warning and above by default) + event_level=events_level, + ), ], **env_options, )