Skip to content

Commit b3cec58

Browse files
mitsuhikosentrivanaantonpirker
authored
feat: incr -> increment for metrics (#2588)
Co-authored-by: Ivana Kellyerova <ivana.kellyerova@sentry.io> Co-authored-by: Anton Pirker <anton.pirker@sentry.io>
1 parent 6c74bfb commit b3cec58

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

sentry_sdk/metrics.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def _get_aggregator_and_update_tags(key, tags):
751751
return client.metrics_aggregator, local_aggregator, updated_tags
752752

753753

754-
def incr(
754+
def increment(
755755
key, # type: str
756756
value=1.0, # type: float
757757
unit="none", # type: MeasurementUnit
@@ -768,6 +768,10 @@ def incr(
768768
)
769769

770770

771+
# alias as incr is relatively common in python
772+
incr = increment
773+
774+
771775
class _Timing(object):
772776
def __init__(
773777
self,

tests/test_metrics.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def parse_metrics(bytes):
5858

5959
@minimum_python_37_with_gevent
6060
@pytest.mark.forked
61-
def test_incr(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
61+
def test_increment(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
6262
sentry_init(
6363
release="fun-release",
6464
environment="not-fun-env",
@@ -67,7 +67,8 @@ def test_incr(sentry_init, capture_envelopes, maybe_monkeypatched_threading):
6767
ts = time.time()
6868
envelopes = capture_envelopes()
6969

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

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

493494
Hub.current.flush()
494495

@@ -589,7 +590,7 @@ def test_metric_summaries(
589590
with start_transaction(
590591
op="stuff", name="/foo", source=TRANSACTION_SOURCE_ROUTE
591592
) as transaction:
592-
metrics.incr("root-counter", timestamp=ts)
593+
metrics.increment("root-counter", timestamp=ts)
593594
with metrics.timing("my-timer-metric", tags={"a": "b"}, timestamp=ts):
594595
for x in range(10):
595596
metrics.distribution("my-dist", float(x), timestamp=ts)
@@ -859,7 +860,7 @@ def before_emit(key, tags):
859860
tags["extra"] = "foo"
860861
del tags["release"]
861862
# this better be a noop!
862-
metrics.incr("shitty-recursion")
863+
metrics.increment("shitty-recursion")
863864
return True
864865

865866
sentry_init(
@@ -873,8 +874,8 @@ def before_emit(key, tags):
873874
)
874875
envelopes = capture_envelopes()
875876

876-
metrics.incr("removed-metric", 1.0)
877-
metrics.incr("actual-metric", 1.0)
877+
metrics.increment("removed-metric", 1.0)
878+
metrics.increment("actual-metric", 1.0)
878879
Hub.current.flush()
879880

880881
(envelope,) = envelopes
@@ -906,7 +907,7 @@ def test_aggregator_flush(
906907
)
907908
envelopes = capture_envelopes()
908909

909-
metrics.incr("a-metric", 1.0)
910+
metrics.increment("a-metric", 1.0)
910911
Hub.current.flush()
911912

912913
assert len(envelopes) == 1
@@ -925,7 +926,7 @@ def test_tag_serialization(
925926
)
926927
envelopes = capture_envelopes()
927928

928-
metrics.incr(
929+
metrics.increment(
929930
"counter",
930931
tags={
931932
"no-value": None,
@@ -970,12 +971,12 @@ def test_flush_recursion_protection(
970971
real_capture_envelope = test_client.transport.capture_envelope
971972

972973
def bad_capture_envelope(*args, **kwargs):
973-
metrics.incr("bad-metric")
974+
metrics.increment("bad-metric")
974975
return real_capture_envelope(*args, **kwargs)
975976

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

978-
metrics.incr("counter")
979+
metrics.increment("counter")
979980

980981
# flush twice to see the inner metric
981982
Hub.current.flush()
@@ -1004,12 +1005,12 @@ def test_flush_recursion_protection_background_flush(
10041005
real_capture_envelope = test_client.transport.capture_envelope
10051006

10061007
def bad_capture_envelope(*args, **kwargs):
1007-
metrics.incr("bad-metric")
1008+
metrics.increment("bad-metric")
10081009
return real_capture_envelope(*args, **kwargs)
10091010

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

1012-
metrics.incr("counter")
1013+
metrics.increment("counter")
10131014

10141015
# flush via sleep and flag
10151016
Hub.current.client.metrics_aggregator._force_flush = True

0 commit comments

Comments
 (0)