From faddf11f7727dc8c92bed098db8a944b93ab04e2 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 1 May 2024 21:29:36 +0100 Subject: [PATCH] Fix TaskErrors being reported to Sentry --- app/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 95134d08..413b5204 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -35,6 +35,14 @@ from sentry_sdk.integrations.flask import FlaskIntegration if os.getenv("SENTRY_DSN"): + def before_send(event, hint): + from app.tasks import TaskError + if "exc_info" in hint: + exc_type, exc_value, tb = hint["exc_info"] + if isinstance(exc_value, TaskError): + return None + return event + environment = os.getenv("SENTRY_ENVIRONMENT") assert environment is not None sentry_sdk.init( @@ -49,6 +57,8 @@ if os.getenv("SENTRY_DSN"): # of sampled transactions. # We recommend adjusting this value in production. profiles_sample_rate=1.0, + + before_send=before_send, )