Skip to content

ref(metrics): Drop negatively sampled metrics immediately - #8425

Open
alexander-alderman-webb wants to merge 7 commits into
webb/sliding-window-metrics-batcher-2from
webb/early-exit-metrics-sampling
Open

alexander-alderman-webb wants to merge 7 commits into
webb/sliding-window-metrics-batcher-2from
webb/early-exit-metrics-sampling

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Drop metrics with a negative decision before applying attributes and calling before_send_metric() .
The random number used for the decision is generated in admit() instead of _add_to_window() and stored on the thread local reservoir.
The _active thread local also holds the window the metric was admitted to if admit() returns True.

To do this we have to make some concessions:

  • before_send_metric() cannot change the metric's name
  • Metrics can be dropped at higher rates if before_send_metric() takes longer than approx. 50 milliseconds to execute. This is a result of the flusher not performing any synchronization and relying on a 50 milliseconds grace period.

This changes the semantics of the sample rate. The sample rate is now relative to metrics captured before invoking any hooks (previously metrics dropped in before_send_metric() did not contribute).

@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review November 30, 2026 09:23
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner November 30, 2026 09:23
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 59777 passed | ⏭️ 3119 skipped | Total: 62896 | Pass Rate: 95.04% | Execution Time: 162m 14s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +320
Passed Tests 📈 +320
Failed Tests —
Skipped Tests —

All tests are passing successfully.

✅ Patch coverage is 93.02% (40 of 43 changed executable lines covered; target 80%).
Project statement coverage is 90.11% (unchanged from base (e3f191d) to head (cf5bb06)).

Changed files with executable lines (4)
File Patch coverage Changed executable lines
sentry_sdk/_lock_free_metrics_batcher.py 90.00% 27/30 covered; missed: 96, 159, 173; partial branches: 158, 168, 172
sentry_sdk/client.py 100.00% 6/6 covered
sentry_sdk/consts.py 100.00% 1/1 covered
sentry_sdk/metrics.py 100.00% 6/6 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8425       +/-##
==========================================
  Coverage    90.11%    90.11%        —%
==========================================
  Files          201       202        +1
  Tracked lines     22199     22488      +289
  Branches      7784      7880       +96
==========================================
+ Hits         20004     20264      +260
- Misses        2195      2224       +29
- Partials      1283      1302       +19

Generated by Coverage Action

@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/early-exit-metrics-sampling branch from 8fd5e82 to 11f431e Compare November 30, 2026 09:57
@alexander-alderman-webb
alexander-alderman-webb force-pushed the webb/early-exit-metrics-sampling branch from 11f431e to dc72f2f Compare November 30, 2026 10:02
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit cf5bb06.

Main concerns: data sent to Sentry, reach, host performance.

Rules that block low also fired:

  • R5: dependencies or bundled SDK versions changed: setup.py
  • R6: build or release configuration changed: setup.py

This label is a hint for reviewers, not an approval.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 30, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants