Skip to content

Commit d0d70a5

Browse files
authored
feat: Do not spam sentry_sdk.warnings logger w/ Spotlight (#4219)
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.
1 parent 4dcd538 commit d0d70a5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Diff for: sentry_sdk/spotlight.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, url):
3838
# type: (str) -> None
3939
self.url = url
4040
self.http = urllib3.PoolManager()
41-
self.tries = 0
41+
self.fails = 0
4242

4343
def capture_envelope(self, envelope):
4444
# type: (Envelope) -> None
@@ -54,9 +54,18 @@ def capture_envelope(self, envelope):
5454
},
5555
)
5656
req.close()
57+
self.fails = 0
5758
except Exception as e:
58-
# TODO: Implement buffering and retrying with exponential backoff
59-
sentry_logger.warning(str(e))
59+
if self.fails < 2:
60+
sentry_logger.warning(str(e))
61+
self.fails += 1
62+
elif self.fails == 2:
63+
self.fails += 1
64+
sentry_logger.warning(
65+
"Looks like Spotlight is not running, will keep trying to send events but will not log errors."
66+
)
67+
# omitting self.fails += 1 in the `else:` case intentionally
68+
# to avoid overflowing the variable if Spotlight never becomes reachable
6069

6170

6271
try:

0 commit comments

Comments
 (0)