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): diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 3f8b6049d8..98afea6f02 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -700,8 +700,8 @@ def should_summarize_metric(key, tags): with start_transaction( op="stuff", name="/foo", source=TRANSACTION_SOURCE_ROUTE ) as transaction: - metrics.timing("foo", value=1.0, tags={"a": "b"}, timestamp=ts) - metrics.timing("foo", value=1.0, tags={"b": "c"}, timestamp=ts) + metrics.timing("foo", value=3.0, tags={"a": "b"}, timestamp=ts) + metrics.timing("foo", value=2.0, tags={"b": "c"}, timestamp=ts) metrics.timing("bar", value=1.0, tags={"a": "b"}, timestamp=ts) Hub.current.flush() @@ -719,34 +719,31 @@ def should_summarize_metric(key, tags): # Measurement Attachment t = transaction.items[0].get_transaction_event()["_metrics_summary"] - assert t == { - "d:foo@second": [ - { - "tags": { - "a": "b", - "environment": "not-fun-env", - "release": "fun-release@1.0.0", - "transaction": "/foo", - }, - "min": 1.0, - "max": 1.0, - "count": 1, - "sum": 1.0, - }, - { - "tags": { - "b": "c", - "environment": "not-fun-env", - "release": "fun-release@1.0.0", - "transaction": "/foo", - }, - "min": 1.0, - "max": 1.0, - "count": 1, - "sum": 1.0, - }, - ] - } + assert len(t["d:foo@second"]) == 2 + assert { + "tags": { + "a": "b", + "environment": "not-fun-env", + "release": "fun-release@1.0.0", + "transaction": "/foo", + }, + "min": 3.0, + "max": 3.0, + "count": 1, + "sum": 3.0, + } in t["d:foo@second"] + assert { + "tags": { + "b": "c", + "environment": "not-fun-env", + "release": "fun-release@1.0.0", + "transaction": "/foo", + }, + "min": 2.0, + "max": 2.0, + "count": 1, + "sum": 2.0, + } in t["d:foo@second"] def test_tag_normalization(sentry_init, capture_envelopes):