You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1ed55d2
Browse filesBrowse the repository at this point in the historyBrowse files
authored
feat(nextjs): Mark pageloads of cached pages (#25318)
When Next.js serves a page from its cache (an ISR page, or a
`cacheComponents` shell that was prerendered at runtime), the pageload
starts its own trace and has no server span. That is correct, but in
Sentry it looks like missing server instrumentation.
While Next.js prerenders a document, the server now writes a
`sentry-cache-origin` meta tag with the `sentry-trace` value of the
prerender (instead of nothing). The client never continues it: it sets
`page.server_rendering.type` on the pageload (`static` when the whole
page came from the cache, `partially_static` when parts of it rendered
for this request) and links the prerender with a `cache_origin` link,
both at span start, so `tracesSampler` and `ignoreSpans` see them. Like
a `use cache` hit, the pageload links only a sampled prerender.
So the fixes of #25141 still hold: a cached page does not attach its
visitors to a request that was not theirs, and a `sampled=0` value in
the tag cannot drop their pageloads. Pages from `next build` get no tag,
because the SDK does not run during the build.
The attribute and the tag are named without Next.js in them on purpose:
other frameworks with prerendering (Nuxt, SvelteKit, Astro, React
Router) can set the same attribute. `page.server_rendering.type` is
being added to `@sentry/conventions` in
getsentry/sentry-conventions#740; `cache_origin` is already a documented
`sentry.link.type` value and is what the cache lifecycle view in Sentry
reads.
Refs JS-3886
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: s1gr1d <32902192+s1gr1d@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,10 @@
10
10
11
11
`@SentryCron` now sends the schedule and time zone from the method's `@Cron()` decorator, so Sentry creates the monitor on the first run. If you use `@SentryCron` without a `schedule`, Sentry now creates missing monitors, which are billed, and overwrites schedules and time zones set by hand. Pass `fromCronDecorator: false` to turn this off.
12
12
13
+
- **feat(nextjs): Mark pageloads of cached pages ([#25318](https://github.com/getsentry/sentry-javascript/pull/25318))**
14
+
15
+
When Next.js serves a page from its cache, for example an ISR page or a `cacheComponents` shell, the pageload now has the `page.server_rendering.type` attribute. It is `static` if the whole page came from the cache, and `partially_static` if parts of it rendered for this request. Then the pageload stays connected to this request, as before. If the request that rendered the cached page was sampled, the pageload also links to it. So in Sentry, a cached page no longer looks like missing server instrumentation.
16
+
13
17
Work in this release was contributed by @lazerg and @chiliec. Thank you for your contributions!
Copy file name to clipboardExpand all lines: dev-packages/e2e-tests/test-applications/nextjs-16-cacheComponents/tests/cacheOrigin-pageloadConnection.spec.ts
0 commit comments