Increase Sentry pageload sample rate for reliable Web Vitals#17740
Conversation
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Review: tracesSampler pageload check won't fire
The intent here is correct — sampling pageloads at 10% for reliable Web Vitals data while keeping everything else at 1%. However, the samplingContext.attributes?.["sentry.op"] === "pageload" check will never be true, making this functionally identical to the original tracesSampleRate: 0.01.
Why it fails
Tracing through the SDK source (@sentry/core@10.5.0):
_startRootSpanbuildssamplingContext.attributesfrom{ ...spanArguments.attributes }— a spread of explicitly passed attributes only (trace.js:411)tracesSampleris called with those attributes (trace.js:425–434)new SentrySpan(...)is constructed after sampling, and it is only here that[SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.opgets written into attributes (sentrySpan.js:47)
So sentry.op is never present in samplingContext.attributes at sampling time — it is a post-sampling side effect.
What to check instead
The pageload span is started with this explicit attribute (from browserTracingIntegration.js):
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.browser',
}This is available in samplingContext.attributes at sampling time.
The fix:
tracesSampler(samplingContext) {
// 10% of pageloads for reliable Web Vitals data
if (samplingContext.attributes?.["sentry.origin"] === "auto.pageload.browser") {
return 0.1
}
// 1% for everything else
return 0.01
},Caveat: The beforeSampling event hook (trace.js:414) runs just before sampling and allows mutation of spanAttributes. It's possible @sentry/nextjs registers a hook there that injects sentry.op — I didn't fully audit the Next.js integration layer. A quick sanity check with Sentry debug logging in a preview deploy would confirm either way.
Reviewed by Claude (claude-sonnet-4-6)
|
bump @pettinarip |
|
@wackerow thanks. Here is the analysis I made and test to double check it works The conclusion doesn't hold for The review correctly traces the generic Verified locally by logging The current implementation works as intended. |

Summary
tracesSampleRate: 0.01with atracesSamplerfunction ininstrumentation-client.tsContext
Sentry Web Vitals insights showed many pages with exactly "100 pageloads" — this was Sentry extrapolating from a single captured trace (1 × 1/0.01 = 100). Drilling into individual pages confirmed only 1 actual trace, making performance scores statistically unreliable.
Test plan