From 61a2fb9fa287aa6c7bb2327c139fe739806f7d99 Mon Sep 17 00:00:00 2001 From: Zacharias Zacharodimos Date: Sat, 14 Oct 2023 17:00:41 +0200 Subject: [PATCH] sentry: set sentry event id --- invenio_logging/sentry.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/invenio_logging/sentry.py b/invenio_logging/sentry.py index 0c6f372..053752d 100644 --- a/invenio_logging/sentry.py +++ b/invenio_logging/sentry.py @@ -12,7 +12,13 @@ import logging +import sentry_sdk from flask import g +from sentry_sdk import configure_scope +from sentry_sdk.integrations.celery import CeleryIntegration +from sentry_sdk.integrations.flask import FlaskIntegration +from sentry_sdk.integrations.redis import RedisIntegration +from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration from . import config from .ext import InvenioLoggingBase @@ -66,13 +72,6 @@ def install_handler(self, app): def install_sentry_sdk_handler(self, app, logging_exclusions, level): """Install sentry-python sdk log handler.""" - import sentry_sdk - from sentry_sdk import configure_scope - from sentry_sdk.integrations.celery import CeleryIntegration - from sentry_sdk.integrations.flask import FlaskIntegration - from sentry_sdk.integrations.redis import RedisIntegration - from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration - integrations = [FlaskIntegration()] init_kwargs = {} if app.config["LOGGING_SENTRY_CELERY"]: @@ -100,4 +99,7 @@ def add_request_id_sentry_python(self, event, hint): tags = event.get("tags") or [] tags.append(["request_id", g.request_id]) event["tags"] = tags + event_id = sentry_sdk.last_event_id() + if event_id is not None: + g.sentry_event_id = event_id return event