-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Changes from all commits
c354d31
37908a3
23a45c2
5cace1f
4401a98
3197ab6
bc91dd3
755bbef
6259233
fd39406
3be7eee
cd5355b
8dbe5e3
2dc8666
fa43554
2382943
8c5588f
50edc11
758028c
a13b7e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,8 +173,8 @@ internal ITransactionTracer StartTransaction( | |
|
|
||
| bool? isSampled = null; | ||
| double? sampleRate = null; | ||
| var sampleRand = dynamicSamplingContext?.Items.TryGetValue("sample_rand", out var dscsampleRand) ?? false | ||
| ? double.Parse(dscsampleRand, NumberStyles.Float, CultureInfo.InvariantCulture) | ||
| var sampleRand = dynamicSamplingContext?.Items.TryGetValue("sample_rand", out var dscSampleRand) ?? false | ||
| ? double.Parse(dscSampleRand, NumberStyles.Float, CultureInfo.InvariantCulture) | ||
| : SampleRandHelper.GenerateSampleRand(context.TraceId.ToString()); | ||
|
|
||
| // TracesSampler runs regardless of whether a decision has already been made, as it can be used to override it. | ||
|
|
@@ -188,14 +188,26 @@ internal ITransactionTracer StartTransaction( | |
| { | ||
| // The TracesSampler trumps all other sampling decisions (even the trace header) | ||
| sampleRate = samplerSampleRate; | ||
| isSampled = SampleRandHelper.IsSampled(sampleRand, sampleRate.Value); | ||
| isSampled = SampleRandHelper.IsSampled(sampleRand, samplerSampleRate); | ||
|
|
||
| // Ensure the actual sampleRate is set on the provided DSC (if any) when the TracesSampler reached a sampling decision | ||
| dynamicSamplingContext = dynamicSamplingContext?.WithSampleRate(samplerSampleRate); | ||
| } | ||
| } | ||
|
|
||
| // If the sampling decision isn't made by a trace sampler we check the trace header first (from the context) or | ||
| // finally fallback to Random sampling if the decision has been made by no other means | ||
| sampleRate ??= _options.TracesSampleRate ?? 0.0; | ||
| isSampled ??= context.IsSampled ?? SampleRandHelper.IsSampled(sampleRand, sampleRate.Value); | ||
| if (isSampled == null) | ||
| { | ||
| sampleRate = _options.TracesSampleRate ?? 0.0; | ||
| isSampled = context.IsSampled ?? SampleRandHelper.IsSampled(sampleRand, sampleRate.Value); | ||
|
|
||
| if (context.IsSampled is null && _options.TracesSampleRate is not null) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TLDR; I think we can remove the Long versionApologies, I think I got us confused on Slack:
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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. followed-up via #4386 |
||
| { | ||
| // Ensure the actual sampleRate is set on the provided DSC (if any) when not IsSampled upstream but the TracesSampleRate reached a sampling decision | ||
| dynamicSamplingContext = dynamicSamplingContext?.WithSampleRate(_options.TracesSampleRate.Value); | ||
| } | ||
| } | ||
|
|
||
| // Make sure there is a replayId (if available) on the provided DSC (if any). | ||
| dynamicSamplingContext = dynamicSamplingContext?.WithReplayId(_replaySession); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.