Skip to content

fix(sampling): Attribute backpressure as unsampling reason more accurately#6445

Open
sentrivana wants to merge 2 commits into
masterfrom
ivana/fix-backpressure-outcome
Open

fix(sampling): Attribute backpressure as unsampling reason more accurately#6445
sentrivana wants to merge 2 commits into
masterfrom
ivana/fix-backpressure-outcome

Conversation

@sentrivana
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana commented May 29, 2026

Description

Context

If backpressure handling is active, it lowers the effective sample rate.

There are different outcomes for when a span is unsampled due to sample_rate or backpressure.

Behavior

Before this change, if under backpressure, we'd only report backpressure as the reason for unsampling if the monitor lowered the effective sample rate to a falsy value. Which only covers a small portion of unsample decisions made due to backpressure. The rest would be reported as a generic sample_rate drop, potentially leading to confusing reporting. If someone e.g. has a traces_sample_rate of 1.0, they might see spans being dropped because of sample_rate, which is hard to justify.

In this PR, we try to do a better job at determining whether backpressure was actually the reason a span was dropped and emit the corresponding outcome.

The idea is, for an unsampled span:

  • if sample_rand would've been higher than the original, non-backpressure sample_rate, the span would've been unsampled regardless of backpressure handling, so the outcome should be sample_rate
  • if sample_rand actually would've been lower than the original sample_rate had the sample_rate not been lowered, the span would've been sampled. In that case backpressure handling is the direct cause and the outcome should be backpressure

Issues

Reminders

@sentrivana sentrivana changed the title fix(sampling): Attribute backpressure as unsampling reason fix(sampling): Attribute backpressure as unsampling reason for more spans May 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

Codecov Results 📊

67 passed | Total: 67 | Pass Rate: 100% | Execution Time: 7.51s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 16.67%. Project has 14860 uncovered lines.
✅ Project coverage is 35.12%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/tracing_utils.py 16.67% ⚠️ 5 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    35.12%    35.12%        —%
==========================================
  Files          190       190         —
  Lines        22901     22905        +4
  Branches      7854      7856        +2
==========================================
+ Hits          8044      8045        +1
- Misses       14857     14860        +3
- Partials       715       715         —

Generated by Codecov Action

@sentrivana sentrivana changed the title fix(sampling): Attribute backpressure as unsampling reason for more spans fix(sampling): Attribute backpressure as unsampling reason more accurately May 29, 2026
@sentrivana sentrivana marked this pull request as ready for review May 29, 2026 12:20
@sentrivana sentrivana requested a review from a team as a code owner May 29, 2026 12:20
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool code!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants