Skip to content

Commit 6f033b1

Browse files
authored
feat: Added metrics summary sample rates as options (#60506)
This lands a callback which controls the sample rate of span local metric summaries dynamically. Refs getsentry/sentry-python#2522
1 parent 36f0a18 commit 6f033b1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/sentry/metrics/minimetrics.py

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def before_emit_metric(key: str, tags: Dict[str, Any]) -> bool:
104104
return True
105105

106106

107+
def should_summarize_metric(key: str, tags: Dict[str, Any]) -> bool:
108+
return random.random() < options.get("delightful_metrics.metrics_summary_sample_rate")
109+
110+
107111
class MiniMetricsMetricsBackend(MetricsBackend):
108112
@staticmethod
109113
def _keep_metric(sample_rate: float) -> bool:

src/sentry/utils/sdk.py

+3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ def flush(
432432
enable_metrics=True,
433433
metric_code_locations=options.get("delightful_metrics.enable_code_locations"),
434434
before_emit_metric=minimetrics.before_emit_metric,
435+
# turn summaries on, but filter them dynamically in the callback
436+
metrics_summary_sample_rate=1.0,
437+
should_summarize_metric=minimetrics.should_summarize_metric,
435438
)
436439

437440
sentry_sdk.init(

0 commit comments

Comments
 (0)