Skip to content
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

feat(ddm): Enable metrics related settings by default #2685

Merged
merged 13 commits into from
Jan 30, 2024
4 changes: 2 additions & 2 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ def _capture_envelope(envelope):

self.metrics_aggregator = None # type: Optional[MetricsAggregator]
experiments = self.options.get("_experiments", {})
if experiments.get("enable_metrics"):
if experiments.get("enable_metrics", True):
from sentry_sdk.metrics import MetricsAggregator

self.metrics_aggregator = MetricsAggregator(
capture_func=_capture_envelope,
enable_code_locations=bool(
experiments.get("metric_code_locations")
experiments.get("metric_code_locations", True)
),
)

Expand Down
6 changes: 5 additions & 1 deletion sentry_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@
if transaction_name:
updated_tags.setdefault("transaction", transaction_name)
if scope._span is not None:
sample_rate = experiments.get("metrics_summary_sample_rate") or 0.0
sample_rate = experiments.get("metrics_summary_sample_rate")

Check warning on line 722 in sentry_sdk/metrics.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/metrics.py#L722

Added line #L722 was not covered by tests
# 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

Check warning on line 726 in sentry_sdk/metrics.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/metrics.py#L726

Added line #L726 was not covered by tests
should_summarize_metric_callback = experiments.get(
"should_summarize_metric"
)
Expand Down
23 changes: 14 additions & 9 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: utf-8

import pytest
import sys
import time
import linecache
Expand Down Expand Up @@ -418,7 +418,7 @@ def test_gauge(sentry_init, capture_envelopes):
sentry_init(
release="[email protected]",
environment="not-fun-env",
_experiments={"enable_metrics": True},
_experiments={"enable_metrics": True, "metric_code_locations": False},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -450,7 +450,7 @@ def test_multiple(sentry_init, capture_envelopes):
sentry_init(
release="[email protected]",
environment="not-fun-env",
_experiments={"enable_metrics": True},
_experiments={"enable_metrics": True, "metric_code_locations": False},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -503,7 +503,7 @@ def test_transaction_name(sentry_init, capture_envelopes):
sentry_init(
release="[email protected]",
environment="not-fun-env",
_experiments={"enable_metrics": True},
_experiments={"enable_metrics": True, "metric_code_locations": False},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -536,12 +536,16 @@ def test_transaction_name(sentry_init, capture_envelopes):
}


def test_metric_summaries(sentry_init, capture_envelopes):
@pytest.mark.parametrize(
"sample_rate",
[1.0, None]
)
def test_metric_summaries(sentry_init, capture_envelopes, sample_rate):
sentry_init(
release="[email protected]",
environment="not-fun-env",
enable_tracing=True,
_experiments={"enable_metrics": True, "metrics_summary_sample_rate": 1.0},
_experiments={"enable_metrics": True, "metrics_summary_sample_rate": sample_rate},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -644,7 +648,7 @@ def test_metrics_summary_disabled(sentry_init, capture_envelopes):
release="[email protected]",
environment="not-fun-env",
enable_tracing=True,
_experiments={"enable_metrics": True},
_experiments={"enable_metrics": True, "metrics_summary_sample_rate": 0.0},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -750,7 +754,7 @@ def test_tag_normalization(sentry_init, capture_envelopes):
sentry_init(
release="[email protected]",
environment="not-fun-env",
_experiments={"enable_metrics": True},
_experiments={"enable_metrics": True, "metric_code_locations": False},
)
ts = time.time()
envelopes = capture_envelopes()
Expand Down Expand Up @@ -805,6 +809,7 @@ def before_emit(key, tags):
environment="not-fun-env",
_experiments={
"enable_metrics": True,
"metric_code_locations": False,
"before_emit_metric": before_emit,
},
)
Expand Down Expand Up @@ -850,7 +855,7 @@ def test_tag_serialization(sentry_init, capture_envelopes):
sentry_init(
release="fun-release",
environment="not-fun-env",
_experiments={"enable_metrics": True},
_experiments={"enable_metrics": True, "metric_code_locations": False},
)
envelopes = capture_envelopes()

Expand Down
Loading