Skip to content
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

feat(core): Add inheritOrSampleWith helper to traceSampler #15277

Merged
merged 4 commits into from
Feb 4, 2025

Conversation

lforst
Copy link
Member

@lforst lforst commented Feb 3, 2025

We found in getsentry/sentry-docs#12544 that the proposed ux is horrible because nobody would understand what it does, so we're adding a helper that facilitates inheriting a sampling decision that also allows for catching more edge-cases without worsening ux and is self explanatory in what it does.

sampleRate = options.tracesSampler(samplingContext);
sampleRate = options.tracesSampler({
...samplingContext,
inheritOrSampleWith(fallbackSampleRate) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
inheritOrSampleWith(fallbackSampleRate) {
inheritOrSampleWith: (fallbackSampleRate) => {

is this maybe slightly cleaner regarding this context? 🤔


// Fallback if parent sample rate is not on the incoming trace (e.g. if there is no baggage)
if (typeof samplingContext.parentSampled === 'boolean') {
return 1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return 1;
return Number(samplingContext.parentSampled);

!! otherwise this would propagate 1 for false :D

Copy link
Contributor

github-actions bot commented Feb 4, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.94 KB - -
@sentry/browser - with treeshaking flags 22.81 KB - -
@sentry/browser (incl. Tracing) 35.82 KB +0.11% +39 B 🔺
@sentry/browser (incl. Tracing, Replay) 72.62 KB +0.05% +37 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 66.17 KB +0.05% +29 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 76.87 KB +0.05% +37 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 89.36 KB +0.04% +36 B 🔺
@sentry/browser (incl. Feedback) 39.64 KB - -
@sentry/browser (incl. sendFeedback) 27.57 KB - -
@sentry/browser (incl. FeedbackAsync) 32.35 KB - -
@sentry/react 24.78 KB - -
@sentry/react (incl. Tracing) 37.71 KB +0.11% +42 B 🔺
@sentry/vue 27.14 KB +0.13% +36 B 🔺
@sentry/vue (incl. Tracing) 37.53 KB +0.1% +36 B 🔺
@sentry/svelte 23.07 KB - -
CDN Bundle 24.25 KB - -
CDN Bundle (incl. Tracing) 35.96 KB +0.11% +38 B 🔺
CDN Bundle (incl. Tracing, Replay) 70.6 KB +0.07% +44 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 75.74 KB +0.06% +41 B 🔺
CDN Bundle - uncompressed 70.85 KB - -
CDN Bundle (incl. Tracing) - uncompressed 106.73 KB +0.14% +143 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 217.58 KB +0.07% +143 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 230.15 KB +0.07% +143 B 🔺
@sentry/nextjs (client) 38.68 KB +0.11% +43 B 🔺
@sentry/sveltekit (client) 36.33 KB +0.11% +40 B 🔺
@sentry/node 156.55 KB +0.03% +46 B 🔺
@sentry/node - without tracing 97.56 KB - -
@sentry/aws-serverless 107.11 KB +0.04% +40 B 🔺

View base workflow run

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

sweet!

@lforst lforst merged commit a3e08ad into develop Feb 4, 2025
145 checks passed
@lforst lforst deleted the lforst-inhert-or-sample-with branch February 4, 2025 14:29
@mydea
Copy link
Member

mydea commented Feb 4, 2025

Should we backport this? 🤔 I think it may be worth it, makes docs much easier in that regard..?

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