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: Added metrics summary sample rates as options #60506

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sentry/metrics/minimetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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
4 changes: 3 additions & 1 deletion src/sentry/utils/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def is_current_event_safe():
"""

with configure_scope() as scope:

# Scope was explicitly marked as unsafe
if scope._tags.get(UNSAFE_TAG):
return False
Expand Down Expand Up @@ -432,6 +431,9 @@ def flush(
sdk_options.setdefault("_experiments", {}).update(
enable_metrics=True,
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