Browse Source

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 https://github.com/getsentry/sentry-python/pull/2522
Armin Ronacher 1 year ago
parent
commit
6f033b1a26
2 changed files with 7 additions and 0 deletions
  1. 4 0
      src/sentry/metrics/minimetrics.py
  2. 3 0
      src/sentry/utils/sdk.py

+ 4 - 0
src/sentry/metrics/minimetrics.py

@@ -104,6 +104,10 @@ def before_emit_metric(key: str, tags: Dict[str, Any]) -> bool:
     return True
 
 
+def should_summarize_metric(key: str, tags: Dict[str, Any]) -> bool:
+    return random.random() < options.get("delightful_metrics.metrics_summary_sample_rate")
+
+
 class MiniMetricsMetricsBackend(MetricsBackend):
     @staticmethod
     def _keep_metric(sample_rate: float) -> bool:

+ 3 - 0
src/sentry/utils/sdk.py

@@ -432,6 +432,9 @@ def configure_sdk():
         enable_metrics=True,
         metric_code_locations=options.get("delightful_metrics.enable_code_locations"),
         before_emit_metric=minimetrics.before_emit_metric,
+        # turn summaries on, but filter them dynamically in the callback
+        metrics_summary_sample_rate=1.0,
+        should_summarize_metric=minimetrics.should_summarize_metric,
     )
 
     sentry_sdk.init(