From 2c957c30828564b5ff184a12d46e37a3b499e75d Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Mon, 31 Mar 2025 18:20:06 +0300 Subject: [PATCH] feat: Do not spam sentry_sdk.warnings logger w/ Spotlight Sometimes one may have Spotlight turned on in the SDK but not have the sidecar running or reachable. In that case we spam the console with every event as they fail to reach Spotlight. This patch limits the fail warnings to 3: the first 2 are actual errors and the final one is a note about shutting up. --- sentry_sdk/spotlight.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index c2473b77e9..4ac427b9c1 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -38,7 +38,7 @@ def __init__(self, url): # type: (str) -> None self.url = url self.http = urllib3.PoolManager() - self.tries = 0 + self.fails = 0 def capture_envelope(self, envelope): # type: (Envelope) -> None @@ -54,9 +54,18 @@ def capture_envelope(self, envelope): }, ) req.close() + self.fails = 0 except Exception as e: - # TODO: Implement buffering and retrying with exponential backoff - sentry_logger.warning(str(e)) + if self.fails < 2: + sentry_logger.warning(str(e)) + self.fails += 1 + elif self.fails == 2: + self.fails += 1 + sentry_logger.warning( + "Looks like Spotlight is not running, will keep trying to send events but will not log errors." + ) + # omitting self.fails += 1 in the `else:` case intentionally + # to avoid overflowing the variable if Spotlight never becomes reachable try: