Skip to content

feat: incr -> increment for metrics #2588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sentry_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def _get_aggregator_and_update_tags(key, tags):
return client.metrics_aggregator, local_aggregator, updated_tags


def incr(
def increment(
key, # type: str
value=1.0, # type: float
unit="none", # type: MeasurementUnit
Expand All @@ -768,6 +768,10 @@ def incr(
)


# alias as incr is relatively common in python
incr = increment


class _Timing(object):
def __init__(
self,
Expand Down
29 changes: 15 additions & 14 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse_metrics(bytes):

@minimum_python_37_with_gevent
@pytest.mark.forked
def test_incr(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
def test_increment(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
sentry_init(
release="fun-release",
environment="not-fun-env",
Expand All @@ -67,7 +67,8 @@ def test_incr(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
ts = time.time()
envelopes = capture_envelopes()

metrics.incr("foobar", 1.0, tags={"foo": "bar", "blub": "blah"}, timestamp=ts)
metrics.increment("foobar", 1.0, tags={"foo": "bar", "blub": "blah"}, timestamp=ts)
# python specific alias
metrics.incr("foobar", 2.0, tags={"foo": "bar", "blub": "blah"}, timestamp=ts)
Hub.current.flush()

Expand Down Expand Up @@ -487,8 +488,8 @@ def test_multiple(sentry_init, capture_envelopes):
metrics.gauge("my-gauge", 20.0, tags={"x": "y"}, timestamp=ts)
metrics.gauge("my-gauge", 30.0, tags={"x": "y"}, timestamp=ts)
for _ in range(10):
metrics.incr("counter-1", 1.0, timestamp=ts)
metrics.incr("counter-2", 1.0, timestamp=ts)
metrics.increment("counter-1", 1.0, timestamp=ts)
metrics.increment("counter-2", 1.0, timestamp=ts)

Hub.current.flush()

Expand Down Expand Up @@ -589,7 +590,7 @@ def test_metric_summaries(
with start_transaction(
op="stuff", name="/foo", source=TRANSACTION_SOURCE_ROUTE
) as transaction:
metrics.incr("root-counter", timestamp=ts)
metrics.increment("root-counter", timestamp=ts)
with metrics.timing("my-timer-metric", tags={"a": "b"}, timestamp=ts):
for x in range(10):
metrics.distribution("my-dist", float(x), timestamp=ts)
Expand Down Expand Up @@ -859,7 +860,7 @@ def before_emit(key, tags):
tags["extra"] = "foo"
del tags["release"]
# this better be a noop!
metrics.incr("shitty-recursion")
metrics.increment("shitty-recursion")
return True

sentry_init(
Expand All @@ -873,8 +874,8 @@ def before_emit(key, tags):
)
envelopes = capture_envelopes()

metrics.incr("removed-metric", 1.0)
metrics.incr("actual-metric", 1.0)
metrics.increment("removed-metric", 1.0)
metrics.increment("actual-metric", 1.0)
Hub.current.flush()

(envelope,) = envelopes
Expand Down Expand Up @@ -906,7 +907,7 @@ def test_aggregator_flush(
)
envelopes = capture_envelopes()

metrics.incr("a-metric", 1.0)
metrics.increment("a-metric", 1.0)
Hub.current.flush()

assert len(envelopes) == 1
Expand All @@ -925,7 +926,7 @@ def test_tag_serialization(
)
envelopes = capture_envelopes()

metrics.incr(
metrics.increment(
"counter",
tags={
"no-value": None,
Expand Down Expand Up @@ -970,12 +971,12 @@ def test_flush_recursion_protection(
real_capture_envelope = test_client.transport.capture_envelope

def bad_capture_envelope(*args, **kwargs):
metrics.incr("bad-metric")
metrics.increment("bad-metric")
return real_capture_envelope(*args, **kwargs)

monkeypatch.setattr(test_client.transport, "capture_envelope", bad_capture_envelope)

metrics.incr("counter")
metrics.increment("counter")

# flush twice to see the inner metric
Hub.current.flush()
Expand Down Expand Up @@ -1004,12 +1005,12 @@ def test_flush_recursion_protection_background_flush(
real_capture_envelope = test_client.transport.capture_envelope

def bad_capture_envelope(*args, **kwargs):
metrics.incr("bad-metric")
metrics.increment("bad-metric")
return real_capture_envelope(*args, **kwargs)

monkeypatch.setattr(test_client.transport, "capture_envelope", bad_capture_envelope)

metrics.incr("counter")
metrics.increment("counter")

# flush via sleep and flag
Hub.current.client.metrics_aggregator._force_flush = True
Expand Down