Skip to content

Conversation

@wyattjoh
Copy link
Member

@wyattjoh wyattjoh commented Jan 22, 2026

What?

Adds comprehensive OpenTelemetry tracing spans to the App Router render pipeline, covering both build-time prerendering and runtime prefetch scenarios.

Why?

When debugging or optimizing applications, it's helpful to understand where time is being spent during rendering. These spans provide visibility into:

Build-time (Cache Components prerender):

  • Prospective RSC Payload generation
  • Prospective Server Prerender (to fill caches)
  • Cache Ready Wait (waiting for all cache reads)
  • Prospective Client Prerender (HTML prerender to fill client caches)
  • Final RSC Payload generation (with warmed caches)
  • Final Server Prerender (with task-based abort)
  • Final Client Prerender (with task-based abort)

Runtime (prefetch):

  • Runtime Prospective RSC Payload
  • Runtime Prospective Server Prerender
  • Runtime Cache Ready Wait
  • Runtime Final RSC Payload
  • Runtime Final Server Prerender

Dynamic Flight Rendering:

  • generateDynamicFlightRenderResult span for RSC streaming responses

How?

  1. Added AppRenderSpan.generateDynamicFlightRenderResult for dynamic flight result generation
  2. Added runtime prerender spans to PrerenderSpan enum for prefetch scenarios
  3. Updated span naming to use consistent prospective/final terminology
  4. Wrapped relevant code paths with getTracer().trace() calls

Note: To expose these spans with OpenTelemetry traces, set the NEXT_OTEL_VERBOSE=1 environment variable.

Add tracing spans to visualize the different phases of the Cache
Components prerender pipeline in prerenderToStream:

- Initial RSC Payload generation
- Initial Server Prerender (prospective render to fill caches)
- Cache Ready Wait (waiting for all cache reads to complete)
- Initial Client Prerender (HTML prerender to fill client caches)
- Final RSC Payload generation (with warmed caches)
- Final Server Prerender (final RSC render with task-based abort)
- Final Client Prerender (final HTML render with task-based abort)

These spans help developers understand the performance characteristics
of their Cache Components-enabled applications during build time.
@wyattjoh wyattjoh force-pushed the wyattjoh/app-render-tracing branch from e1b0e42 to 53e7e26 Compare January 22, 2026 20:58
@nextjs-bot
Copy link
Collaborator

Stats from current PR

🔴 1 regression

Metric Canary PR Change Trend
node_modules Size 460 MB 461 MB 🔴 +120 kB (+0%) ▁▁▁▁▁
📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 455ms 455ms ▁▁▁▁▁
Cold (Ready in log) 437ms 437ms ▁▂▁▁▁
Cold (First Request) 1.150s 1.145s ▁▃▂▁▃
Warm (Listen) 455ms 456ms ▁▁▁▂▁
Warm (Ready in log) 443ms 441ms ▁▁▁▁▁
Warm (First Request) 344ms 340ms ▂▁▁▂▂
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 455ms 455ms ▁▁▁▁▁
Cold (Ready in log) 440ms 439ms ▁▁▁▁▁
Cold (First Request) 1.839s 1.844s ▁▁▁▁▁
Warm (Listen) 455ms 455ms ▁▁▁▁▁
Warm (Ready in log) 440ms 439ms ▁▁▁▁▁
Warm (First Request) 1.836s 1.851s ▁▁▁▁▁

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.306s 4.336s ▁▁▁▂▁
Cached Build 4.274s 4.240s ▁▁▁▁▁
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 14.094s 14.145s ▄▂▂▂▂
Cached Build 14.212s 14.259s ▄▄▂▂▁
node_modules Size 460 MB 461 MB 🔴 +120 kB (+0%) ▁▁▁▁▁
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles: **432 kB** → **432 kB** ✅ -58 B

82 files with content-based hashes (individual files not comparable between builds)

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 761 B 769 B 🔴 +8 B (+1%)
Total 761 B 769 B ⚠️ +8 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 451 B 450 B
Total 451 B 450 B ✅ -1 B

📦 Webpack

Client

Main Bundles
Canary PR Change
2086.HASH.js gzip 169 B N/A -
2161-HASH.js gzip 5.41 kB N/A -
2747-HASH.js gzip 4.48 kB N/A -
4322-HASH.js gzip 52.7 kB N/A -
ec793fe8-HASH.js gzip 62.3 kB N/A -
framework-HASH.js gzip 59.8 kB 59.8 kB
main-app-HASH.js gzip 251 B 254 B 🔴 +3 B (+1%)
main-HASH.js gzip 38.7 kB 39.1 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
1596.HASH.js gzip N/A 169 B -
2658-HASH.js gzip N/A 52.4 kB -
6349-HASH.js gzip N/A 4.46 kB -
7019-HASH.js gzip N/A 5.43 kB -
b17a3386-HASH.js gzip N/A 62.3 kB -
Total 226 kB 226 kB ⚠️ +55 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 194 B 193 B
_error-HASH.js gzip 182 B 182 B
css-HASH.js gzip 336 B 335 B
dynamic-HASH.js gzip 1.8 kB 1.8 kB
edge-ssr-HASH.js gzip 256 B 256 B
head-HASH.js gzip 352 B 349 B
hooks-HASH.js gzip 385 B 384 B
image-HASH.js gzip 580 B 580 B
index-HASH.js gzip 259 B 258 B
link-HASH.js gzip 2.5 kB 2.51 kB
routerDirect..HASH.js gzip 319 B 317 B
script-HASH.js gzip 385 B 387 B
withRouter-HASH.js gzip 316 B 315 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.97 kB 7.96 kB ✅ -8 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 126 kB 126 kB
page.js gzip 244 kB 240 kB 🟢 4.41 kB (-2%)
Total 370 kB 366 kB ✅ -4.2 kB
Middleware
Canary PR Change
middleware-b..fest.js gzip 616 B 619 B
middleware-r..fest.js gzip 155 B 156 B
middleware.js gzip 33.2 kB 33.4 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 34.8 kB 35 kB ⚠️ +223 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 738 B 738 B
Total 738 B 738 B
Build Cache
Canary PR Change
0.pack gzip 3.71 MB 3.72 MB 🔴 +10.8 kB (+0%)
index.pack gzip 102 kB 102 kB
index.pack.old gzip 102 kB 101 kB 🟢 1.36 kB (-1%)
Total 3.91 MB 3.92 MB ⚠️ +8.98 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 306 kB 306 kB
app-page-exp..prod.js gzip 163 kB 163 kB
app-page-tur...dev.js gzip 306 kB 306 kB
app-page-tur..prod.js gzip 163 kB 163 kB
app-page-tur...dev.js gzip 302 kB 303 kB
app-page-tur..prod.js gzip 161 kB 161 kB
app-page.run...dev.js gzip 303 kB 303 kB
app-page.run..prod.js gzip 161 kB 161 kB
app-route-ex...dev.js gzip 69.4 kB 69.5 kB
app-route-ex..prod.js gzip 48.2 kB 48.2 kB
app-route-tu...dev.js gzip 69.4 kB 69.5 kB
app-route-tu..prod.js gzip 48.2 kB 48.2 kB
app-route-tu...dev.js gzip 69 kB 69.1 kB
app-route-tu..prod.js gzip 47.9 kB 47.9 kB
app-route.ru...dev.js gzip 68.9 kB 69.1 kB
app-route.ru..prod.js gzip 47.9 kB 47.9 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 42.4 kB 42.5 kB
pages-api-tu..prod.js gzip 32.2 kB 32.2 kB
pages-api.ru...dev.js gzip 42.4 kB 42.5 kB
pages-api.ru..prod.js gzip 32.2 kB 32.2 kB
pages-turbo....dev.js gzip 51.7 kB 51.8 kB
pages-turbo...prod.js gzip 38.8 kB 38.8 kB
pages.runtim...dev.js gzip 51.7 kB 51.8 kB
pages.runtim..prod.js gzip 38.8 kB 38.8 kB
server.runti..prod.js gzip 62.3 kB 62.3 kB
Total 2.73 MB 2.73 MB ⚠️ +3.02 kB
📝 Changed Files (16 files)

Files with changes:

  • app-page-exp..ntime.dev.js
  • app-page-exp..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page.runtime.dev.js
  • app-page.runtime.prod.js
  • app-route-ex..ntime.dev.js
  • app-route-tu..ntime.dev.js
  • app-route-tu..ntime.dev.js
  • app-route.runtime.dev.js
  • pages-api-tu..ntime.dev.js
  • pages-api.runtime.dev.js
  • pages-turbo...ntime.dev.js
  • pages.runtime.dev.js
View diffs
app-page-exp..ntime.dev.js

Diff too large to display

app-page-exp..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js

Diff too large to display

app-page-tur..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js

Diff too large to display

app-page-tur..time.prod.js

Diff too large to display

app-page.runtime.dev.js

Diff too large to display

app-page.runtime.prod.js

Diff too large to display

app-route-ex..ntime.dev.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route-tu..ntime.dev.js

Diff too large to display

app-route.runtime.dev.js

Diff too large to display

pages-api-tu..ntime.dev.js

Diff too large to display

pages-api.runtime.dev.js

Diff too large to display

pages-turbo...ntime.dev.js

Diff too large to display

pages.runtime.dev.js

Diff too large to display

- Add span for generateDynamicFlightRenderResult
- Add runtime prerender spans for prefetch scenarios
- Improve span naming consistency (prospective/final pattern)
@nextjs-bot
Copy link
Collaborator

Failing test suites

Commit: edd96f3 | About building and testing Next.js

pnpm test-start test/e2e/app-dir/segment-cache/prefetch-runtime/prefetch-runtime.test.ts (job)

  • runtime prefetching > in a private cache > can completely prefetch a page that uses cookies and no uncached IO (DD)
Expand output

● runtime prefetching › in a private cache › can completely prefetch a page that uses cookies and no uncached IO

apiRequestContext.fetch: socket hang up
Call log:
  - → GET http://localhost:37901/in-private-cache/cookies-only?_rsc=180y0
  -   user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/130.0.6723.31 Safari/537.36
  -   accept: */*
  -   accept-encoding: gzip,deflate,br
  -   cookie: testCookie=initialValue
  -   next-test-fetch-priority: low
  -   referer: http://localhost:37901/
  -   next-router-prefetch: 1
  -   next-router-segment-prefetch: /!KGRlZmF1bHQp/in-private-cache
  -   next-url: /
  -   rsc: 1
  -   sec-ch-ua: "Chromium";v="130", "HeadlessChrome";v="130", "Not?A_Brand";v="99"
  -   sec-ch-ua-mobile: ?0
  -   sec-ch-ua-platform: "Linux"

  225 |             // server; we pass the request to the server the immediately.
  226 |             result: (async () => {
> 227 |               const originalResponse = await page.request.fetch(request, {
      |                                                           ^
  228 |                 maxRedirects: 0,
  229 |               })
  230 |

  at fetch (lib/router-act.ts:227:59)
  at lib/router-act.ts:245:13
  at routeHandler (lib/router-act.ts:257:7)

● runtime prefetching › in a private cache › can completely prefetch a page that uses cookies and no uncached IO

apiRequestContext.fetch: socket hang up
Call log:
  - → GET http://localhost:37901/in-private-cache/cookies-only?_rsc=180y0
  -   user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/130.0.6723.31 Safari/537.36
  -   accept: */*
  -   accept-encoding: gzip,deflate,br
  -   cookie: testCookie=initialValue
  -   next-test-fetch-priority: low
  -   referer: http://localhost:37901/
  -   next-router-prefetch: 1
  -   next-router-segment-prefetch: /!KGRlZmF1bHQp/in-private-cache
  -   next-url: /
  -   rsc: 1
  -   sec-ch-ua: "Chromium";v="130", "HeadlessChrome";v="130", "Not?A_Brand";v="99"
  -   sec-ch-ua-mobile: ?0
  -   sec-ch-ua-platform: "Linux"

  225 |             // server; we pass the request to the server the immediately.
  226 |             result: (async () => {
> 227 |               const originalResponse = await page.request.fetch(request, {
      |                                                           ^
  228 |                 maxRedirects: 0,
  229 |               })
  230 |

  at fetch (lib/router-act.ts:227:59)
  at lib/router-act.ts:245:13
  at routeHandler (lib/router-act.ts:257:7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants