Skip to content

Commit

Permalink
chore: Remove experimental metric summary options (#2957)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Apr 10, 2024
1 parent a422dd7 commit 18ccb8f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 138 deletions.
2 changes: 0 additions & 2 deletions sentry_sdk/consts.py
Expand Up @@ -47,8 +47,6 @@
"transport_zlib_compression_level": Optional[int],
"transport_num_pools": Optional[int],
"enable_metrics": Optional[bool],
"metrics_summary_sample_rate": Optional[float],
"should_summarize_metric": Optional[Callable[[str, MetricTags], bool]],
"before_emit_metric": Optional[Callable[[str, MetricTags], bool]],
"metric_code_locations": Optional[bool],
},
Expand Down
17 changes: 2 additions & 15 deletions sentry_sdk/metrics.py
Expand Up @@ -710,8 +710,6 @@ def _get_aggregator_and_update_tags(key, tags):
if client is None or client.metrics_aggregator is None:
return None, None, tags

experiments = client.options.get("_experiments", {})

updated_tags = dict(tags or ()) # type: Dict[str, MetricTagValue]
updated_tags.setdefault("release", client.options["release"])
updated_tags.setdefault("environment", client.options["environment"])
Expand All @@ -727,20 +725,9 @@ def _get_aggregator_and_update_tags(key, tags):
if transaction_name:
updated_tags.setdefault("transaction", transaction_name)
if scope._span is not None:
sample_rate = experiments.get("metrics_summary_sample_rate")
# We default the sample rate of metrics summaries to 1.0 only when the sample rate is `None` since we
# want to honor the user's decision if they pass a valid float.
if sample_rate is None:
sample_rate = 1.0
should_summarize_metric_callback = experiments.get(
"should_summarize_metric"
)
if random.random() < sample_rate and (
should_summarize_metric_callback is None
or should_summarize_metric_callback(key, updated_tags)
):
local_aggregator = scope._span._get_local_aggregator()
local_aggregator = scope._span._get_local_aggregator()

experiments = client.options.get("_experiments", {})
before_emit_callback = experiments.get("before_emit_metric")
if before_emit_callback is not None:
with recursion_protection() as in_metrics:
Expand Down
122 changes: 1 addition & 121 deletions tests/test_metrics.py
Expand Up @@ -571,18 +571,13 @@ def test_transaction_name(

@minimum_python_37_with_gevent
@pytest.mark.forked
@pytest.mark.parametrize("sample_rate", [1.0, None])
def test_metric_summaries(
sentry_init, capture_envelopes, sample_rate, maybe_monkeypatched_threading
sentry_init, capture_envelopes, maybe_monkeypatched_threading
):
sentry_init(
release="fun-release@1.0.0",
environment="not-fun-env",
enable_tracing=True,
_experiments={
"enable_metrics": True,
"metrics_summary_sample_rate": sample_rate,
},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -680,121 +675,6 @@ def test_metric_summaries(
}


@minimum_python_37_with_gevent
@pytest.mark.forked
def test_metrics_summary_disabled(
sentry_init, capture_envelopes, maybe_monkeypatched_threading
):
sentry_init(
release="fun-release@1.0.0",
environment="not-fun-env",
enable_tracing=True,
_experiments={"enable_metrics": True, "metrics_summary_sample_rate": 0.0},
)
ts = time.time()
envelopes = capture_envelopes()

with start_transaction(
op="stuff", name="/foo", source=TRANSACTION_SOURCE_ROUTE
) as transaction:
with metrics.timing("my-timer-metric", tags={"a": "b"}, timestamp=ts):
pass

Hub.current.flush()

(transaction, envelope) = envelopes

# Metrics Emission
assert envelope.items[0].headers["type"] == "statsd"
m = parse_metrics(envelope.items[0].payload.get_bytes())

assert len(m) == 1
assert m[0][1] == "my-timer-metric@second"
assert m[0][2] == "d"
assert len(m[0][3]) == 1
assert m[0][4] == {
"a": "b",
"transaction": "/foo",
"release": "fun-release@1.0.0",
"environment": "not-fun-env",
}

# Measurement Attachment
t = transaction.items[0].get_transaction_event()
assert "_metrics_summary" not in t
assert "_metrics_summary" not in t["spans"][0]


@minimum_python_37_with_gevent
@pytest.mark.forked
def test_metrics_summary_filtered(
sentry_init, capture_envelopes, maybe_monkeypatched_threading
):
def should_summarize_metric(key, tags):
return key == "foo"

sentry_init(
release="fun-release@1.0.0",
environment="not-fun-env",
enable_tracing=True,
_experiments={
"enable_metrics": True,
"metrics_summary_sample_rate": 1.0,
"should_summarize_metric": should_summarize_metric,
},
)
ts = time.time()
envelopes = capture_envelopes()

with start_transaction(
op="stuff", name="/foo", source=TRANSACTION_SOURCE_ROUTE
) as transaction:
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()

(transaction, envelope) = envelopes

# Metrics Emission
assert envelope.items[0].headers["type"] == "statsd"
m = parse_metrics(envelope.items[0].payload.get_bytes())

assert len(m) == 3
assert m[0][1] == "bar@second"
assert m[1][1] == "foo@second"
assert m[2][1] == "foo@second"

# Measurement Attachment
t = transaction.items[0].get_transaction_event()["_metrics_summary"]
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"]


@minimum_python_37_with_gevent
@pytest.mark.forked
def test_tag_normalization(
Expand Down

0 comments on commit 18ccb8f

Please sign in to comment.