feat: Propagate and use a sampling random#14989
Merged
Conversation
Contributor
size-limit report 📦
|
❌ 1 Tests Failed:
View the full list of 1 ❄️ flaky tests
To view more test analytics, go to the Test Analytics Dashboard |
added 8 commits
January 13, 2025 13:42
andreiborza
approved these changes
Jan 16, 2025
Comment on lines
60
to
61
| // Now we roll the dice. Math.random is inclusive of 0, but not of 1, so strict < is safe here. In case sampleRate is | ||
| // a boolean, the < comparison will cause it to be automatically cast to 1 if it's true and 0 if it's false. |
Member
There was a problem hiding this comment.
m: The comment here is outdated now.
| parentSpanId, | ||
| sampled: parentSampled, | ||
| dsc: dynamicSamplingContext || {}, // If we have traceparent data but no DSC it means we are not head of trace and we must freeze it | ||
| sampleRand: sampleRand, |
Member
There was a problem hiding this comment.
l:
Suggested change
| sampleRand: sampleRand, | |
| sampleRand, |
| return traceparentData.parentSampled | ||
| ? // Returns a sample rand with positive sampling decision [0, sampleRate) | ||
| Math.random() * parsedSampleRate | ||
| : // Returns a sample rand with negative sampling decision [sampleRate, 1] |
Member
There was a problem hiding this comment.
l:
Suggested change
| : // Returns a sample rand with negative sampling decision [sampleRate, 1] | |
| : // Returns a sample rand with negative sampling decision [sampleRate, 1) |
| } | ||
|
|
||
| /** | ||
| * Given any combination of an incoming trace, generate a sample rand based on its defined semantics. |
Member
There was a problem hiding this comment.
l: Maybe we could link to these semantics here
|
|
||
| expect(sampleRand).toStrictEqual(expect.any(Number)); | ||
| expect(sampleRand).not.toBeNaN(); | ||
| expect(sampleRand).toBeGreaterThanOrEqual(0.75); |
Member
There was a problem hiding this comment.
l: I'd also add expect(sampleRand).toBeLessThan(1) for completeness sake
|
|
||
| expect(sampleRand).toStrictEqual(expect.any(Number)); | ||
| expect(sampleRand).not.toBeNaN(); | ||
| expect(sampleRand).toBeLessThan(0.25); |
Member
There was a problem hiding this comment.
l: I'd also add expect(sampleRand).toBeGreaterThan(0) for completeness sake
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.
Ref #14932
Adds a
sample_randto the DSC and asampleRandto the propagation context that is effectively newly generated for every new trace, or based on the rules outlined here: https://develop.sentry.dev/sdk/telemetry/traces/#propagation