-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Propagate Sampling Seed #3951
Propagate Sampling Seed #3951
Conversation
…sactionEndedAsCrashed.Net4_8.verified.txt
…sactionEndedAsCrashed.Net4_8.verified.txt
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.
only got as far as 2 files
@@ -61,6 +68,11 @@ private DynamicSamplingContext( | |||
items.Add("sample_rate", sampleRate.Value.ToString(CultureInfo.InvariantCulture)); | |||
} | |||
|
|||
if (sampleRand is not null) | |||
{ | |||
items.Add("sample_rand", sampleRand.Value.ToString("N4", CultureInfo.InvariantCulture)); |
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.
we want this even if we have sample_rate
in? see line 68
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.
I believe so yes. The docs developer docs indicate:
If sample_rate (inside baggage) and the sampling decision (trailing -1 or -0 from the sentry-trace header) are present in the incoming trace, create sample_rand so that when compared to the incoming sample_rate it would lead to the same sampling decision that is in the sentry-trace header.
Which we're doing... and then we propagate the sample_rand
so that if any downstream nodes can use this in their sampling decision.
@@ -111,6 +123,27 @@ private DynamicSamplingContext( | |||
return null; | |||
} | |||
|
|||
// See https://develop.sentry.dev/sdk/telemetry/traces/#propagated-random-value | |||
if (items.TryGetValue("sample_rand", out var sampleRand)) |
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.
odd that we validate this to be within a range as a float but then we make it a string then try to parse it back out.
Can we rely on the original value and avoid the parsing instead?
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.
I'm not sure I follow. It may or may not be present as a string in the baggage header. If it's present then here we try to cast it to a float and ensure it's in the correct range.
If it's present but malformed then we don't create the DSC from the baggage header.
if (items.TryGetValue("sample_rand", out var sampleRand)) | ||
{ | ||
if (!double.TryParse(sampleRand, NumberStyles.Float, CultureInfo.InvariantCulture, out var rand) || | ||
rand is < 0.0 or >= 1.0) |
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.
didn't we validate this above before adding it to items
? or it could already be in items when the method was caled? in which case wouldn't we be adding it twice? (I add Add so assume it's not a dictionary)
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.
This method is creating a DSC from the baggage header. The BaggageHeader is a pretty simple class that just pulls stuff directly off a certain HTTP header, without any strong opinions about what the items in that header should be. Other vendors might be putting things on that header so we just propagate it, pretty much verbatim (we might add things to it but we never remove things from it).
But we can't control what will be on that baggage header in this SDK. A request could be made to our SDK with a malformed sentry-sample_rand item in the BaggageHeader.
added @cleptric and @buenaflor to check alignment with the other SDKs |
Resolves #3921
Implementation in other SDKs:
sample_rand
in DSC sentry-python#4016Progress
sentry-sample_rand
is read from the DSC and PropagationContext (TwP)sample_rand
when none is provided in BaggageHeadersample_rand
when creating new Transactionssample_rand
in sampling decisionsentry-sample_rand
gets propagated in trace headers