From 2f1e3817f1f20a05d6da15e6c7d3e0e16caa7d32 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 15 Mar 2025 23:04:00 +1100 Subject: [PATCH] Prevent sentry reporting in test mode (#9304) (#9306) (cherry picked from commit cdb445583b8d1949d9c0294aae546c96ab1a4926) Co-authored-by: Oliver --- src/backend/InvenTree/InvenTree/sentry.py | 4 ++++ src/backend/InvenTree/InvenTree/settings.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/InvenTree/InvenTree/sentry.py b/src/backend/InvenTree/InvenTree/sentry.py index b73c5e77f5..d625825772 100644 --- a/src/backend/InvenTree/InvenTree/sentry.py +++ b/src/backend/InvenTree/InvenTree/sentry.py @@ -67,6 +67,10 @@ def init_sentry(dsn, sample_rate, tags): def report_exception(exc): """Report an exception to sentry.io.""" + if settings.TESTING: + # Skip reporting exceptions in testing mode + return + if settings.SENTRY_ENABLED and settings.SENTRY_DSN: if not any(isinstance(exc, e) for e in sentry_ignore_errors()): logger.info('Reporting exception to sentry.io: %s', exc) diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 9bd426935c..198c945e3b 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -873,7 +873,7 @@ 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 and not TESTING: # pragma: no cover init_sentry(SENTRY_DSN, SENTRY_SAMPLE_RATE, inventree_tags) # OpenTelemetry tracing