Conversation
cuva
requested review from
NinjaLikesCheez,
itaybre,
noahsmartin and
philprime
as code owners
September 11, 2026 08:29
…cided sampling SentryTransactionContext accepts parentSampleRate and parentSampleRand, but sentry_sampleTrace never read them. In the parent-decided branch it reported the context's own sampleRate and sampleRand, which the trace-header initializer leaves nil, so a transaction continuing a trace from incoming headers propagated a dynamic sampling context without sample_rate and sample_rand. Relay could then reach a different keep-or-drop decision for it than for the rest of the trace. Inherit the parent values in that branch and fall back to the context's own sampleRate and sampleRand when they are not set.
cuva
force-pushed
the
fix/inherit-parent-sample-rate-and-rand
branch
from
September 11, 2026 08:29
d93fcf4 to
63af451
Compare
NinjaLikesCheez
approved these changes
Sep 15, 2026
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
SentryTransactionContextacceptsparentSampleRateandparentSampleRand(added in #4751), butsentry_sampleTracenever reads them. In the parent-decided branch it reports the context's ownsampleRateandsampleRand, which the trace-header initializer leavesnil. A transaction that continues a trace from incomingsentry-traceandbaggageheaders therefore ends up with a trace context withoutsample_rateandsample_rand, andSentryTraceContextomits them from the outgoing baggage.This change makes the parent-decided branch inherit
parentSampleRateandparentSampleRand, falling back to the context's ownsampleRateandsampleRandwhen the parent values are not set, which preserves the existing behaviour for callers that set those directly.💡 Motivation and Context
The dynamic sampling context spec requires a received DSC to be treated as frozen and propagated unchanged, and the propagated random value section requires
sample_randto be the same across a trace so Relay reaches one consistent keep-or-drop decision. Today a Cocoa transaction that continues a trace drops both values, so Relay can sample that transaction independently of the rest of the trace.Our use case is a desktop app where a web view (JavaScript SDK) starts the trace and the native macOS host continues it for the requests it handles. The only workaround is to also set
sampleRateandsampleRandon the context by hand, which relies on the sampler not reading the parent fields.💚 How did you test it?
SentryHubTests. The twoshouldInheritParentSampleRateAndRandtests andshouldPropagateThemInTraceContextfail onmainwithnilfor both values and pass with this change. TheshouldUseContextSampleRateAndRandtest covers the fallback.make test-macos FOR_AGENTS=true ONLY_TESTING=SentryTests/SentryHubTests: 122 tests, 0 failures.clang-formatreports no changes forSentrySampling.m;make analyzerun on the change.📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.