Skip to content

Commit

Permalink
Merge branch 'master' into ivana/reduce-py-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker authored Dec 7, 2023
2 parents b489d5e + 22bdc4d commit 8c4d9cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
9 changes: 8 additions & 1 deletion sentry_sdk/spotlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
57 changes: 27 additions & 30 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit 8c4d9cb

Please sign in to comment.