FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(sampling): `sentry-trace` should take precedence over baggage by sentrivana · Pull Request #6863 · getsentry/sentry-python · GitHub

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

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 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 Bot commented Jul 23, 2026

Copy link
Copy Markdown

PY-2618

github-actions Bot commented Jul 23, 2026
edited
Loading

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 marked this pull request as ready for review July 23, 2026 09:44
sentrivana requested a review from a team as a code owner July 23, 2026 09:44

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

sentrivana Jul 23, 2026
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Fixed in ddc7386

sentrivana enabled auto-merge (squash) July 23, 2026 14:21
sentrivana merged commit 3e163b1 into master Jul 23, 2026
258 checks passed
sentrivana deleted the ivana/fix-incorrect-sampling-decision branch July 23, 2026 14:35
mgaligniana pushed a commit to mgaligniana/sentry-python that referenced this pull request Aug 9, 2026
…tsentry#6863)

### 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
* closes
https://linear.app/getsentry/issue/PY-2618/incorrect-sampling-decision-propagated-in-some-cases-in-span-streaming
* closes getsentry#6856

#### Reminders
- Please add tests to validate your changes, and lint your code using
`uv run ruff`.
- Add GH Issue ID _&_ Linear ID (if applicable)
- PR title should use [conventional
commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type)
style (`feat:`, `fix:`, `ref:`, `meta:`)
- For external contributors:
[CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md),
[Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord
community](https://discord.gg/Ww9hbqr)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL