Skip to content

Commit

Permalink
[FIX] sentry: mute sentry event if logger is muted
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed May 29, 2024
1 parent 311fe7e commit 944d4e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions sentry/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
9 changes: 8 additions & 1 deletion sentry/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 944d4e0

Please sign in to comment.