From 45dc0abda593808778f3a1b4fb05ddde2fb3af8b Mon Sep 17 00:00:00 2001 From: Rainer Koirikivi Date: Tue, 14 May 2024 13:50:42 +0300 Subject: [PATCH] Ignore Pyro5 address recovery errors in sentry --- bridge_node/bridge/sentry.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bridge_node/bridge/sentry.py b/bridge_node/bridge/sentry.py index 27130e8..7b5f4b2 100644 --- a/bridge_node/bridge/sentry.py +++ b/bridge_node/bridge/sentry.py @@ -2,6 +2,7 @@ import warnings import sentry_sdk +from Pyro5.errors import CommunicationError, SecurityError logger = logging.getLogger(__name__) @@ -11,7 +12,21 @@ def init_sentry(dsn): warnings.warn("Sentry DSN not set, Sentry disabled", stacklevel=2) return + def before_send(event, hint): + if "exc_info" in hint: + exc_value = hint["exc_info"][1] + + # TODO: Address recovered from Pyro5 handshake is sometimes not valid. Not sure why this would happen -- + # it needs to be investigated, but for now let's just ignore + if isinstance(exc_value, CommunicationError | SecurityError): + if "does not match any of the allowed addresses" in str(exc_value): + logger.info("Ignoring Pyro5 error: %s", exc_value) + return None + + return event + logger.info("Initializing Sentry") sentry_sdk.init( dsn=dsn, + before_send=before_send, )