-
-
Notifications
You must be signed in to change notification settings - Fork 225
fix: overwrite DSC sample_rate when sampling
#4374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ion has been made
| sampleRate = _options.TracesSampleRate ?? 0.0; | ||
| isSampled = context.IsSampled ?? SampleRandHelper.IsSampled(sampleRand, sampleRate.Value); | ||
|
|
||
| if (context.IsSampled is null && _options.TracesSampleRate is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TLDR; I think we can remove the if block here.
Long version
Apologies, I think I got us confused on Slack:
contextis of typeITransactionContext... I think when an upstream span is sampled,context.IsParentSampledwill be true (notcontext.IsSampled).- Whether or not the parent span was sampled is probably not relevant. It's possible that our process has a different sample-rate configured to the upstream node... as long as we use the same sample rand, we maximise (not guarantee) the chance of having a complete trace. If we have a sample-rand of 0.5 and the upstream node has a sample rate of 0.75 but we have a sample rate of 0.25 (and assuming I've understood the requirements) I think we need to sample out in this case and put our own sample-rate (0.25) on the header... so we just overwrite in this scenario.
- I'm not 100% sure whether that's how sampling is implemented at Sentry though... maybe we only support different sample rates on different nodes via the TracesSampler function. @cleptric do you know?
- If
context.IsSampled == trueI think that means the SDK user has forced sampling to true (passing it explicitly via the call toStartTransaction).
On the bright side, if all of the above is correct, it means it should be trivial to implement the logic to force sampling (per the other SDKs)... basically we can force a sample-rate of 0.0 or 1.0 if context.IsSampled is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
followed-up via #4386
Fixes #4392
sample_ratewhen sampling #4392Overwrite Dynamic Sampling Context (DSC)
sample_ratewhen sampling decision is madeFixes: https://linear.app/getsentry/project/update-the-dscs-sample-rate-e4e8398e6acc/overview
See also: getsentry/team-sdks#117
Symptom
The Trace-View's extrapolation is based on the
"sample_rate"of the Dynamic Sampling Context.Changes
When a DSC is available, then its immutability is ignored and its
sample_rateoverwrittenTracesSampleris used and applied, then its resulting Sample-Rate is setTracesSampleRateis used and applied, that Sample-Rate is setITransactionContext.IsSampledis set (when an upstream sampling decision has been made), then the DSC"sample_rate"is kept unchangedAlso, refactored
test/Sentry.Tests/HubTests.cshub.ConfigureScopewithhub.ScopeManager.ConfigureScopefor assertionssample_ratewhen sampling #4374 (comment)Unchanged
SampleRateon neither the resultingTransactionTracernorUnsampledTransactionNote
The
sample_rateoverwritten in the DSC is now the sameSampleRateset on the resultingTransactionTracerorUnsampledTransaction(TransactionTracer.SampleRate/UnsampledTransaction.SampleRate) with the following precedenceSentryOptions.TracesSamplerreaches a sampling decision (is not null and returns not null)ITransactionContext.IsSampledis set (an upstream sampling decision has been made)SentryOptions.TracesSampleRatereaches a sampling decision (is not null)