diff --git a/InvenTree/InvenTree/exceptions.py b/InvenTree/InvenTree/exceptions.py index 1b7dcbb20e..1b61d36b87 100644 --- a/InvenTree/InvenTree/exceptions.py +++ b/InvenTree/InvenTree/exceptions.py @@ -55,10 +55,17 @@ def exception_handler(exc, context): """Custom exception handler for DRF framework. Ref: https://www.django-rest-framework.org/api-guide/exceptions/#custom-exception-handling - Catches any errors not natively handled by DRF, and re-throws as an error DRF can handle + Catches any errors not natively handled by DRF, and re-throws as an error DRF can handle. + + If sentry error reporting is enabled, we will also provide the original exception to sentry.io """ response = None + if settings.SENTRY_ENABLED and settings.SENTRY_DSN: + # Report this exception to sentry.io + from sentry_sdk import capture_exception + capture_exception(exc) + # Catch any django validation error, and re-throw a DRF validation error if isinstance(exc, DjangoValidationError): exc = DRFValidationError(detail=serializers.as_serializer_error(exc)) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 1aab68d5d6..8164e6bbae 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -568,6 +568,9 @@ SENTRY_DSN = get_setting('INVENTREE_SENTRY_DSN', 'sentry_dsn', INVENTREE_DSN) SENTRY_SAMPLE_RATE = float(get_setting('INVENTREE_SENTRY_SAMPLE_RATE', 'sentry_sample_rate', 0.1)) if SENTRY_ENABLED and SENTRY_DSN: # pragma: no cover + + logger.info("Running with sentry.io integration enabled") + sentry_sdk.init( dsn=SENTRY_DSN, integrations=[DjangoIntegration(), ],