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

sentry: import-detect sentry_sdk usage #81

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
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
16 changes: 14 additions & 2 deletions invenio_logging/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import logging

import sentry_sdk
from flask import g
from sentry_sdk import configure_scope
from sentry_sdk.integrations.celery import CeleryIntegration
Expand All @@ -23,6 +22,11 @@
from . import config
from .ext import InvenioLoggingBase

try:
import sentry_sdk
except ImportError:
sentry_sdk = None


class InvenioLoggingSentry(InvenioLoggingBase):
"""Invenio-Logging extension for Sentry."""
Expand All @@ -35,6 +39,14 @@ def init_app(self, app):
if app.config["SENTRY_DSN"] is None:
return

# If SENTRY_DSN is set, check also that sentry-sdk is installed
if sentry_sdk is None:
app.logger.warning(
"The `SENTRY_DSN` config is set, but `sentry-sdk` is not installed. "
"Please install `sentry-sdk` to use the Sentry logging extension."
)
return

self.install_handler(app)

app.extensions["invenio-logging-sentry"] = self
Expand Down Expand Up @@ -96,7 +108,7 @@ def install_sentry_sdk_handler(self, app, logging_exclusions, level):
in_app_exclude=logging_exclusions,
integrations=integrations,
before_send=self.add_request_id_sentry_python,
**init_kwargs
**init_kwargs,
)
with configure_scope() as scope:
scope.level = level
Expand Down