Skip to content

Conversation

@logaretm
Copy link
Collaborator

@logaretm logaretm commented Nov 12, 2025

Summary

ISR pages will have a sentry-trace and baggage meta tags rendered on them following the initial render or after the first invalidation causing a cached trace id to be present until the next invalidation.

This happens in Next.js 15/16 and both on Turbopack and Webpack.

What I tried and didn't work

I Found no way to conditionally set/unset/change the values set by the clientTraceMetadata option, I found nothing useful on unit async storages, nor re-setting the propagation context works. The clientTraceMetadata gets called way earlier at the app-render.tsx level, which would call our SentryPropagator.inject() then. We cannot intercept it either because it runs before the page wrapper is called.

The main issue is timing:

  • Suppressing the tracing wouldn't work either because it is too late. Ideally we want a way to tell Next to remove those attributes at runtime, or render them conditionally.
  • I also tried setting everything that has to do with sentry-trace or baggage to dummy values as some sort of "marker" for the SDK on the browser side to drop them, but again it is too late since clientTraceMetadata is picked up too early.

Implementation

so I figured a workaround, I decided to do it on the client side by:

  • Marking ISR page routes via the route manifest we already have.
  • In Sentry.init call we remove the tags before the browser integration has had a chance to grab the meta tags.

Not the cleanest way, but I verified the issue by writing tests for it and observing page loads across multiple page visits having the same trace id. The meta deletion forces them to have new id for every visit which is what we want.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.6 kB - -
@sentry/browser - with treeshaking flags 23.09 kB - -
@sentry/browser (incl. Tracing) 41.26 kB - -
@sentry/browser (incl. Tracing, Profiling) 45.53 kB - -
@sentry/browser (incl. Tracing, Replay) 79.73 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.4 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.42 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.58 kB - -
@sentry/browser (incl. Feedback) 41.27 kB - -
@sentry/browser (incl. sendFeedback) 29.27 kB - -
@sentry/browser (incl. FeedbackAsync) 34.2 kB - -
@sentry/react 26.29 kB - -
@sentry/react (incl. Tracing) 43.22 kB - -
@sentry/vue 29.09 kB - -
@sentry/vue (incl. Tracing) 43.03 kB - -
@sentry/svelte 24.61 kB - -
CDN Bundle 26.9 kB - -
CDN Bundle (incl. Tracing) 41.81 kB - -
CDN Bundle (incl. Tracing, Replay) 78.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 83.81 kB - -
CDN Bundle - uncompressed 78.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 124 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 240.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 252.79 kB - -
@sentry/nextjs (client) 45.47 kB +0.28% +126 B 🔺
@sentry/sveltekit (client) 41.64 kB - -
@sentry/node-core 50.86 kB -0.01% -1 B 🔽
@sentry/node 158.03 kB -0.01% -3 B 🔽
@sentry/node - without tracing 92.73 kB -0.01% -2 B 🔽
@sentry/aws-serverless 106.5 kB - -

View base workflow run

@logaretm logaretm force-pushed the awad/js-1152-nextjs-incremental-static-rendering-causes-cached-trace-id branch from 73ec1ba to 54be3bf Compare November 12, 2025 20:38
@logaretm logaretm marked this pull request as ready for review November 13, 2025 10:05
@logaretm logaretm requested a review from chargome November 13, 2025 10:06
@logaretm logaretm requested a review from Lms24 November 13, 2025 10:38
@logaretm logaretm force-pushed the awad/js-1152-nextjs-incremental-static-rendering-causes-cached-trace-id branch from 289f39c to 12badfa Compare November 13, 2025 19:10
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.

nextjs incremental static rendering causes cached trace id, leading to merged client-side transactions from different users/requests

2 participants