Skip to content

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

Merged
merged 21 commits into from
Jan 16, 2025
Merged

feat: Propagate and use a sampling random #14989

merged 21 commits into from
Jan 16, 2025

Conversation

lforst
Copy link
Contributor

@lforst lforst commented Jan 13, 2025

Ref #14932

Adds a sample_rand to the DSC and a sampleRand 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

Copy link
Contributor

github-actions bot commented Jan 13, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.86 KB +0.17% +39 B 🔺
@sentry/browser - with treeshaking flags 21.53 KB +0.13% +27 B 🔺
@sentry/browser (incl. Tracing) 35.56 KB +0.18% +62 B 🔺
@sentry/browser (incl. Tracing, Replay) 72.37 KB +0.14% +103 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.86 KB +0.12% +74 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 76.62 KB +0.13% +98 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 88.63 KB +0.1% +87 B 🔺
@sentry/browser (incl. Feedback) 39.08 KB +0.06% +23 B 🔺
@sentry/browser (incl. sendFeedback) 27.5 KB +0.14% +39 B 🔺
@sentry/browser (incl. FeedbackAsync) 32.27 KB +0.07% +23 B 🔺
@sentry/react 25.56 KB +0.1% +24 B 🔺
@sentry/react (incl. Tracing) 38.36 KB +0.26% +99 B 🔺
@sentry/vue 26.95 KB - -
@sentry/vue (incl. Tracing) 37.31 KB +0.23% +85 B 🔺
@sentry/svelte 22.99 KB +0.12% +26 B 🔺
CDN Bundle 24.27 KB +0.53% +129 B 🔺
CDN Bundle (incl. Tracing) 35.92 KB +0.23% +82 B 🔺
CDN Bundle (incl. Tracing, Replay) 70.55 KB +0.13% +93 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 75.68 KB +0.12% +87 B 🔺
CDN Bundle - uncompressed 70.81 KB +0.58% +418 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 106.42 KB +0.36% +390 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 217.25 KB +0.18% +390 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.78 KB +0.17% +390 B 🔺
@sentry/nextjs (client) 38.47 KB +0.24% +91 B 🔺
@sentry/sveltekit (client) 36.11 KB +0.23% +83 B 🔺
@sentry/node 161.32 KB +0.06% +96 B 🔺
@sentry/node - without tracing 97.11 KB +0.08% +70 B 🔺
@sentry/aws-serverless 127 KB +0.08% +94 B 🔺

View base workflow run

Copy link

codecov bot commented Jan 13, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
695 1 694 300
View the full list of 1 ❄️ flaky tests
client-app-routing-instrumentation.test.ts Creates a navigation transaction for app router routes

Flake rate in main: 20.00% (Passed 8 times, Failed 2 times)

Stack Traces | 30s run time
client-app-routing-instrumentation.test.ts:19:5 Creates a navigation transaction for app router routes

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@lforst lforst requested a review from mydea January 14, 2025 15:45
@lforst lforst marked this pull request as ready for review January 14, 2025 15:45
@lforst lforst requested review from a team as code owners January 14, 2025 15:45
@lforst lforst requested a review from andreiborza January 15, 2025 09:40
Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.
Copy link
Member

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l:

Suggested change
: // 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.
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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

@lforst lforst merged commit 95cc948 into develop Jan 16, 2025
157 checks passed
@lforst lforst deleted the lforst-sample-rand branch January 16, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants