Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit Sentry logging integration #3262

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ Sentry reporting can be enabled via the following settings:
kinto.sentry_dsn = https://[email protected]/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:

::
Expand Down
2 changes: 2 additions & 0 deletions kinto/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions kinto/core/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
# Capture debug and above as breadcrumbs
level=breadcrumbs_level,
# Send warnings and above as events
event_level=events_level,
leplatrem marked this conversation as resolved.
Show resolved Hide resolved
),
],
**env_options,
)
Expand Down