-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Propagate and use a sampling random #14989
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
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 |
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.
LGTM
// 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. |
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.
m: The comment here is outdated now.
@@ -65,6 +76,7 @@ export function propagationContextFromHeaders( | |||
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, |
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.
l:
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] |
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.
l:
: // Returns a sample rand with negative sampling decision [sampleRate, 1] | |
: // Returns a sample rand with negative sampling decision [sampleRate, 1) |
@@ -82,3 +94,30 @@ export function generateSentryTraceHeader( | |||
} | |||
return `${traceId}-${spanId}${sampledString}`; | |||
} | |||
|
|||
/** | |||
* Given any combination of an incoming trace, generate a sample rand based on its defined semantics. |
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.
l: Maybe we could link to these semantics here
|
||
expect(sampleRand).toStrictEqual(expect.any(Number)); | ||
expect(sampleRand).not.toBeNaN(); | ||
expect(sampleRand).toBeGreaterThanOrEqual(0.75); |
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.
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); |
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.
l: I'd also add expect(sampleRand).toBeGreaterThan(0)
for completeness sake
Ref #14932
Adds a
sample_rand
to the DSC and asampleRand
to 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