From 416ecf4dc52508f12618a11bb354b5605597c546 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, 10 insertions(+), 6 deletions(-) diff --git a/invenio_logging/sentry.py b/invenio_logging/sentry.py index 0c6f372..d20e257 100644 --- a/invenio_logging/sentry.py +++ b/invenio_logging/sentry.py @@ -14,6 +14,13 @@ from flask import g +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 + from . import config from .ext import InvenioLoggingBase @@ -66,12 +73,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 = {} @@ -100,4 +101,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