From e962a0380bc7dee880092ab61cdfe34d3fc44748 Mon Sep 17 00:00:00 2001 From: Kevin Burnett <18027+burnettk@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:49:17 +0000 Subject: [PATCH] avoid sending MethodNotAllowed to sentry (#1888) Co-authored-by: burnettk --- .../src/spiffworkflow_backend/exceptions/api_error.py | 2 ++ .../src/spiffworkflow_backend/services/monitoring_service.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py b/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py index 763c86692..63282445b 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/exceptions/api_error.py @@ -258,6 +258,8 @@ def should_notify_sentry(exception: Exception) -> bool: return False # like a 404, 405 Method Not Allowed: The method is not allowed for the requested URL + # it doesn't seem to work to exclude this here. i guess it happens before it gets to our app? + # excluded via before_send in configure_sentry if isinstance(exception, MethodNotAllowed): return False diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/monitoring_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/monitoring_service.py index c8e68f58c..9ea1e9588 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/monitoring_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/monitoring_service.py @@ -8,6 +8,7 @@ import flask.wrappers import sentry_sdk from prometheus_flask_exporter import ConnexionPrometheusMetrics # type: ignore from sentry_sdk.integrations.flask import FlaskIntegration +from werkzeug.exceptions import MethodNotAllowed from werkzeug.exceptions import NotFound @@ -60,6 +61,8 @@ def configure_sentry(app: flask.app.Flask) -> None: # NotFound is mostly from web crawlers if isinstance(exc_value, NotFound): return None + if isinstance(exc_value, MethodNotAllowed): + return None return event sentry_errors_sample_rate = app.config.get("SPIFFWORKFLOW_BACKEND_SENTRY_ERRORS_SAMPLE_RATE")