Skip to content

fix(sampling): sentry-trace should take precedence over baggage#6863

Merged
sentrivana merged 5 commits into
masterfrom
ivana/fix-incorrect-sampling-decision
Jul 23, 2026
Merged

fix(sampling): sentry-trace should take precedence over baggage#6863
sentrivana merged 5 commits into
masterfrom
ivana/fix-incorrect-sampling-decision

Conversation

@sentrivana

Copy link
Copy Markdown
Contributor

Description

We were making the wrong sampling decision in a specific case: when the incoming sentry-trace ended in -0, but the incoming baggage had a combination of sentry-sample_rate and sentry-sample_rand that would've actually produced a positive sampling decision, we would prioritize the information from the baggage over the parent sampling decision from sentry-trace.

This PR aligns the behavior with the legacy codepath, where we'd set parent_sampled as the new sample_rate.

Issues

Reminders

@sentrivana sentrivana changed the title fix(sampling): sentry-trace takes precedence over baggage fix(sampling): sentry-trace should take precedence over baggage Jul 23, 2026
@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

PY-2618

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

95930 passed | ⏭️ 6340 skipped | Total: 102270 | Pass Rate: 93.8% | Execution Time: 336m 27s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +415
Passed Tests 📈 +377
Failed Tests
Skipped Tests 📈 +38

All tests are passing successfully.

✅ Patch coverage is 83.33%. Project has 2512 uncovered lines.
✅ Project coverage is 89.67%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/tracing_utils.py 83.33% ⚠️ 1 Missing and 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.65%    89.67%    +0.02%
==========================================
  Files          193       193         —
  Lines        24324     24321        -3
  Branches      8572      8572         —
==========================================
+ Hits         21807     21809        +2
- Misses        2517      2512        -5
- Partials      1395      1397        +2

Generated by Codecov Action

@sentrivana
sentrivana marked this pull request as ready for review July 23, 2026 09:44
@sentrivana
sentrivana requested a review from a team as a code owner July 23, 2026 09:44

@ericapisani ericapisani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just noticed a small thing

Comment thread tests/tracing/test_span_streaming.py Outdated
Comment on lines +1028 to +1030
"sentry-sample_rate": "0.75",
"sentry-sample_rand": "0.500000",
"sentry-sampled": "true",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not add these to the initial definition of incoming_baggage above?

@sentrivana sentrivana Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing! Copied this test from another one that only did this conditionally and missed this.

Fixed in ddc7386

@sentrivana
sentrivana enabled auto-merge (squash) July 23, 2026 14:21
@sentrivana
sentrivana merged commit 3e163b1 into master Jul 23, 2026
257 of 258 checks passed
@sentrivana
sentrivana deleted the ivana/fix-incorrect-sampling-decision branch July 23, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect sampling decision propagated in some cases in span streaming

3 participants