From 22bdc4d1abf45eeaffb6e4261230b28696655eef Mon Sep 17 00:00:00 2001 From: Daniel Griesser Date: Thu, 7 Dec 2023 15:59:32 +0100 Subject: [PATCH] ref: Add max tries to Spotlight (#2571) Co-authored-by: Anton Pirker --- sentry_sdk/spotlight.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index 9b686bfc89..3d02ee74f0 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -17,9 +17,15 @@ def __init__(self, url): # type: (str) -> None self.url = url self.http = urllib3.PoolManager() + self.tries = 0 def capture_envelope(self, envelope): # type: (Envelope) -> None + if self.tries > 3: + logger.warning( + "Too many errors sending to Spotlight, stop sending events there." + ) + return body = io.BytesIO() envelope.serialize_into(body) try: @@ -33,7 +39,8 @@ def capture_envelope(self, envelope): ) req.close() except Exception as e: - logger.exception(str(e)) + self.tries += 1 + logger.warning(str(e)) def setup_spotlight(options):