mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Fix sentry.io integration for DRF exceptions (#4569)
- Previous work to "consume" exceptions raised during API access prevented exception information from reaching sentry.io - Makes subsequent debugging much more difficult - Now these exceptions are explicitly sent to sentry.io (if the integration is enabled)
This commit is contained in:
parent
4cd1d2eebe
commit
6ebe8c61c5
@ -55,10 +55,17 @@ def exception_handler(exc, context):
|
|||||||
"""Custom exception handler for DRF framework.
|
"""Custom exception handler for DRF framework.
|
||||||
|
|
||||||
Ref: https://www.django-rest-framework.org/api-guide/exceptions/#custom-exception-handling
|
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
|
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
|
# Catch any django validation error, and re-throw a DRF validation error
|
||||||
if isinstance(exc, DjangoValidationError):
|
if isinstance(exc, DjangoValidationError):
|
||||||
exc = DRFValidationError(detail=serializers.as_serializer_error(exc))
|
exc = DRFValidationError(detail=serializers.as_serializer_error(exc))
|
||||||
|
@ -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))
|
SENTRY_SAMPLE_RATE = float(get_setting('INVENTREE_SENTRY_SAMPLE_RATE', 'sentry_sample_rate', 0.1))
|
||||||
|
|
||||||
if SENTRY_ENABLED and SENTRY_DSN: # pragma: no cover
|
if SENTRY_ENABLED and SENTRY_DSN: # pragma: no cover
|
||||||
|
|
||||||
|
logger.info("Running with sentry.io integration enabled")
|
||||||
|
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
dsn=SENTRY_DSN,
|
dsn=SENTRY_DSN,
|
||||||
integrations=[DjangoIntegration(), ],
|
integrations=[DjangoIntegration(), ],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user