Skip to content

Commit b7ac009

Browse files
committed
feat: Added metrics summary sample rates as options
1 parent f8ba0d6 commit b7ac009

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/sentry/metrics/minimetrics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def before_emit_metric(key: str, tags: Dict[str, Any]) -> bool:
8888
return True
8989

9090

91+
def should_summarize_metric(key: str, tags: Dict[str, Any]) -> bool:
92+
return random.random() < options.get("delightful_metrics.metrics_summary_sample_rate")
93+
94+
9195
class MiniMetricsMetricsBackend(MetricsBackend):
9296
@staticmethod
9397
def _keep_metric(sample_rate: float) -> bool:

src/sentry/utils/sdk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def is_current_event_safe():
9797
"""
9898

9999
with configure_scope() as scope:
100-
101100
# Scope was explicitly marked as unsafe
102101
if scope._tags.get(UNSAFE_TAG):
103102
return False
@@ -432,6 +431,9 @@ def flush(
432431
sdk_options.setdefault("_experiments", {}).update(
433432
enable_metrics=True,
434433
before_emit_metric=minimetrics.before_emit_metric,
434+
# turn summaries on, but filter them dynamically in the callback
435+
metrics_summary_sample_rate=1.0,
436+
should_summarize_metric=minimetrics.should_summarize_metric,
435437
)
436438

437439
sentry_sdk.init(

0 commit comments

Comments
 (0)