Skip to content

Commit

Permalink
global: make sentry-sdk optional
Browse files Browse the repository at this point in the history
* Import-detects `sentry_sdk` so that we can remove the hard dependency.
  • Loading branch information
slint committed Dec 2, 2024
1 parent 62cdfb7 commit 5246a0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions invenio_rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@

from datetime import timezone

import sentry_sdk
from flask import Response, abort, current_app, g, jsonify, make_response, request
from flask.views import MethodView
from werkzeug.exceptions import HTTPException

from .errors import RESTException, SameContentException

try:
import sentry_sdk
except ImportError:
sentry_sdk = None


def create_api_errorhandler(**kwargs):
r"""Create an API error handler.
Expand All @@ -40,7 +44,7 @@ def api_errorhandler(e):
return e.get_response()
elif isinstance(e, HTTPException) and e.description:
kwargs["message"] = e.description
if kwargs.get("status", 400) >= 500:
if kwargs.get("status", 400) >= 500 and sentry_sdk is not None:
sentry_event_id = sentry_sdk.last_event_id()
if sentry_event_id:
kwargs["error_id"] = str(sentry_event_id)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ zip_safe = False
install_requires =
Flask-CORS>=2.1.0
invenio-base>=1.2.5,<2.0.0
invenio-logging[sentry_sdk]>=2.1.0,<3.0.0
invenio-logging>=2.1.0,<3.0.0
itsdangerous>=1.1.0
marshmallow>=2.15.2
webargs>=5.5.0,<6.0.0
Expand Down

0 comments on commit 5246a0e

Please sign in to comment.