Skip to content

Show startup, compilation, and HMR in Request Insights - #101304

Open
wbinnssmith wants to merge 2 commits into
codex/tooling-otel-span-recorderfrom
codex/tooling-request-insights
Open

wbinnssmith wants to merge 2 commits into
codex/tooling-otel-span-recorderfrom
codex/tooling-request-insights

Conversation

@wbinnssmith

@wbinnssmith wbinnssmith commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

What?

Record dev startup, compilation, and HMR through the shared local recorder. Compilation is attached to the request that triggered it, so a cold compile shows up in that request's trace instead of as an untraced gap. Activity with no request behind it gets its own Background entry, including client HMR latency.

The router records the handoff to rendering as a route to render span, so time between routing and rendering, often a cold compile, shows under that span instead of as a gap. A request's start time includes spans that start before BaseServer.handleRequest, such as compile-path and that handoff; request spans still set the end. The router sets the Request Insights opt-in before workers fork, so spans recorded during startup, before any request or render server exists, are kept.

Why?

A cold compile, startup, or HMR used to appear as an untraced gap or not at all, so slow first requests looked like application time.

How?

These spans are ordinary Next.js spans. Background entries show all of their spans by default, and compile-path is visible by default inside requests. The CLI, filters, and trace viewer list Background entries. Producers opt into Request Insights recording explicitly, independently of application OTel configuration. Webpack isn't instrumented: under --webpack, startup and compile-path still appear, but webpack compiles and client HMR latency aren't recorded.

Verification

  • pnpm testonly packages/next/src/server/lib/trace/ packages/next/src/next-devtools/dev-overlay/ packages/next/src/trace/
  • pnpm --filter=next types
  • request-insights.test.ts: "keeps a cold compile before the request span in request timing" and "keeps the router handoff that ends after the request span"
  • pnpm test-dev-turbo and pnpm test-dev-webpack on test/development/app-dir/request-insights-background/ and test/development/app-dir/hmr-trace-timing/. The background HMR case is Turbopack-only (@force-gate turbopack).
  • pnpm test-dev-turbo test/development/app-dir/request-insights/

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch 5 times, most recently from 55f1da9 to 8280b02 Compare November 12, 2026 18:02
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch 2 times, most recently from 4c8d089 to 8019495 Compare November 12, 2026 20:17
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent finished reviewing your changes.
1982e92 • Tue, 17 Nov 2026 01:41:04 GMT

Vercel Agent found issues that need attention.

Issues (2)
packages/next/src/server/lib/trace/request-insights.ts:207-211 — When a cold request compiles before entering BaseServer, the handle-request span overwrites its timing range and clips the newly associated compilation out of the timeline.
packages/next/src/server/lib/trace/request-insights-span-recorder.ts:88-92 — Assigning tooling span types without admitting them to the default trace filter leaves successful startup and HMR activities with empty timelines unless verbose mode is enabled.

Review steps (1m 26s)

Preparing the workspace 25.3s
Analyzing the changes 55.6s
Finalizing the review 5.0s

@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from 8019495 to bf4558c Compare November 12, 2026 20:40
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch 2 times, most recently from d8a3f47 to c704b78 Compare November 12, 2026 21:18
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from c704b78 to 16d46d9 Compare November 12, 2026 21:38
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from 16d46d9 to 6941bfa Compare November 12, 2026 21:48
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from 6941bfa to eed571e Compare November 12, 2026 21:58
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from eed571e to 5afd649 Compare November 12, 2026 22:02
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from e8ea822 to 5b82111 Compare November 25, 2026 00:44

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review reviewed 5b82111 and isn’t approving it: this repository’s review rules call for a person’s review. 2 open findings are listed in its review summary and inline. View the full report

Comment thread packages/next/src/build/output/store.ts Resolved
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from 7d9e9cb to 6c955b6 Compare November 25, 2026 17:36
@wbinnssmith
wbinnssmith removed this pull request from stack #102341 November 25, 2026 17:42

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review reviewed 6c955b6 and isn’t approving it: this repository’s review rules call for a person’s review. 3 open findings are listed in its review summary and inline. View the full report

Comment thread test/unit/turbopack-hmr-latency.test.ts Resolved
@wbinnssmith
wbinnssmith removed this pull request from stack #102372 November 25, 2026 17:49
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch from 6c955b6 to 8328933 Compare November 25, 2026 17:56
@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch 4 times, most recently from f7d9152 to 634363c Compare November 25, 2026 19:29

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review reviewed 634363c and isn’t approving it: this repository’s review rules call for a person’s review. 5 open findings are listed in its review summary and inline. View the full report

@wbinnssmith
wbinnssmith force-pushed the codex/tooling-request-insights branch 3 times, most recently from 76365f1 to 703f1cf Compare November 25, 2026 20:07
vercel[bot]
vercel Bot previously requested changes Nov 25, 2026

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review requests changes on d4c7901: 1 confirmed blocker or major issue, listed in its review summary and inline. View the full report

Comment thread skills/next-performance/SKILL.md Resolved

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review reviewed 0b04da7 and isn’t approving it: this repository’s review rules call for a person’s review. 1 open finding is listed in its review summary and inline. View the full report

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review reviewed 377648a and isn’t approving it: this repository’s review rules call for a person’s review. 1 open finding is listed in its review summary and inline. View the full report

height="880"
/>

Time not covered by a child span belongs to its nearest visible parent. A gap between routing and rendering appears under `route to render`. Compiling the route for the request appears as `compile-path`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Unverified · Minor — Docs point to route to render, but the default trace view hides it

The new guide text says a gap between routing and rendering "appears under route to render". The router records that span with type Router.invokeRender, and DEFAULT_VISIBLE_SPAN_TYPES doesn't include that type. The non-verbose trace view, which is the overlay's default (verbose: false), therefore drops the span, and the gap shows up under no visible parent. Readers following the docs (and the SKILL guidance built on them) won't find the span unless they turn on verbose mode.

Needs your judgment: the review traced this through the code but couldn’t run anything to prove it.

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review requests changes on 72c48a0: 1 confirmed blocker or major issue, listed in its review summary and inline. View the full report

if (!recordRenderHandoff) {
return await render()
}
return await getTracer().trace(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Confirmed · Major — 'route to render' takes the OTel root slot from BaseServer.handleRequest

In dev with experimental.requestInsights on, the router now runs every render inside getTracer().trace(RouterSpan.invokeRender). NextTracerImpl.trace always sets rootSpanIdKey in the context and registers the outermost span as the root, so once an app registers an OTel context manager (for example @vercel/otel in instrumentation.ts), handleRequest is no longer the root. Its finally block then gets undefined from getRootSpanAttributes() and returns early. The handleRequest span is never renamed to 'GET /route', never gets next.route or http.route, and http.route never reaches the host span. The repro nests the two trace() calls the way router-server.ts and base-server.ts do, using the tracer's real code.

Confirmed by running its repro on this commit and on the base: Its repro fails on the head as it says (exit 1); the base fails it differently (exit 1), so what it tests is new in this change.

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review requests changes on 6614f4d: 1 confirmed blocker or major issue, listed in its review summary. View the full report

wbinnssmith and others added 2 commits November 25, 2026 20:10
Rebased onto the Request Insights stack as one commit. The router runs
each request inside its Request Insights identity, so compile-path spans
recorded during route matching attach to the request; drop the history
assertions and the opt-in config from the tooling fixture.

Co-Authored-By: Claude <[email protected]>
import-request-insight-spans now imports local-span-ids directly, so
webpack bundled a second counter into the dev app-page runtimes and
re-imported validation spans could reuse IDs within one trace.
Externalize it alongside the recorder and span store.

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Vercel Agent Verified Review requests changes on b76a06c: 1 confirmed blocker or major issue, listed in its review summary. View the full report

This branch has not been deployed

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

Labels

created-by: Turbopack team PRs by the Turbopack team. Documentation Related to Next.js' official documentation. tests type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant