diff --git a/sentry/hooks.py b/sentry/hooks.py index 2236977c358..aef14c3e662 100644 --- a/sentry/hooks.py +++ b/sentry/hooks.py @@ -53,6 +53,15 @@ def before_send(event, hint): if qualified_name in const.DEFAULT_IGNORED_EXCEPTIONS: return None + # Check if the logger is muted + try: + logger_name = hint["log_record"].name + except AttributeError: + logger_name = None + + if logger_name and not logging.getLogger(logger_name).propagate: + return None + if event.setdefault("tags", {})["include_context"]: cxtest = get_extra_context(odoo.http.request) info_request = ["tags", "user", "extra", "request"] diff --git a/sentry/tests/test_client.py b/sentry/tests/test_client.py index 9832c75ff34..694ccf4d5e4 100644 --- a/sentry/tests/test_client.py +++ b/sentry/tests/test_client.py @@ -10,7 +10,7 @@ from odoo import exceptions from odoo.tests import TransactionCase -from odoo.tools import config +from odoo.tools import config, mute_logger from ..const import to_int_if_defined from ..hooks import initialize_sentry @@ -141,6 +141,13 @@ def test_capture_event(self): level = "error" self.assertEventCaptured(self.client, level, msg) + def test_mute_logger(self): + level, msg = logging.WARNING, "Test event, can be ignored" + with mute_logger(__name__): + self.log(level, msg) + level = "warning" + self.assertEventNotCaptured(self.client, level, msg) + def test_capture_event_exc(self): level, msg = logging.ERROR, "Test event, can be ignored exception" try: