Skip to content

Commit

Permalink
feat: Added metrics summary sample rates as options (#60506)
Browse files Browse the repository at this point in the history
This lands a callback which controls the sample rate of span local
metric summaries dynamically.

Refs getsentry/sentry-python#2522
  • Loading branch information
mitsuhiko committed Nov 27, 2023
1 parent 36f0a18 commit 6f033b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sentry/metrics/minimetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/utils/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ def flush(
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(
Expand Down

0 comments on commit 6f033b1

Please sign in to comment.