Replace Request Insights span recorder with request sessions#95897
Draft
timneutkens wants to merge 1 commit into
Draft
Replace Request Insights span recorder with request sessions#95897timneutkens wants to merge 1 commit into
timneutkens wants to merge 1 commit into
Conversation
## Summary Replace the OpenTelemetry-shaped LocalSpanRecorder and span store with typed, request-scoped profiling sessions. Preserve nested operations, fetch/cache details, errors, and all Request Insights access surfaces while keeping real OpenTelemetry spans independent. Restore live DevTools updates by lazily installing the dev runtime when the bundler subscribes. ## Verification - pnpm build-all - pnpm exec jest packages/next/src/server/lib/trace/request-insights.test.ts packages/next/src/server/lib/trace/tracer.test.ts packages/next/src/server/lib/patch-fetch.test.ts --runInBand - NEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-turbo test/development/app-dir/request-insights/request-insights.test.ts - NEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-webpack test/development/app-dir/request-insights/request-insights.test.ts - NEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-webpack test/e2e/app-dir/app/standalone.test.ts <!-- NEXT_JS_LLM -->
Contributor
Failing test suitesCommit: 3b6f666 | About building and testing Next.js
Expand output● next-server-nft › default mode › should not trace too many files in next-minimal-server.js.nft.json ● next-server-nft › with adapters › should not trace too many files in next-minimal-server.js.nft.json Other failing CI jobs |
Contributor
Stats from current PR🟢 2 improvements
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (19 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffapp-route-ex..ntime.dev.jsDiff too large to display app-route-ex..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route.runtime.dev.jsDiff too large to display app-route.ru..time.prod.jsDiff too large to display server.runtime.prod.jsDiff too large to display pages-api.ru..time.prod.jsDiff too large to display pages.runtime.prod.jsDiff too large to display 📎 Tarball URLCommit: 3b6f666 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Request Insights now models each incoming request as a typed profiling session instead of recording a second, OpenTelemetry-shaped span tree.
At a high level, the development server creates one request session around
BaseServer.handleRequest. Existing framework trace points add lightweight, nested operations to that session, whilepatch-fetchrecords typed fetch and cache details directly. When the handler settles, the runtime finalizes the request metadata and publishes one completed snapshot to the Request Insights subscribers used by DevTools, the development endpoint, CLI, and MCP surfaces.This replaces
LocalSpanRecorder,SpanStore, and the separate request-identity context with a single development-only runtime containing:Why this is different
Previously, Request Insights behaved like a fallback OpenTelemetry implementation: it created local span objects, stored OTel-shaped data, and coupled request profiling to tracer behavior. That made ownership and lifecycle difficult to follow, duplicated request identity and fetch data, and risked changing tracing semantics when no real provider was installed.
The new runtime is an observer of framework activity, not a span provider. Real OpenTelemetry spans remain owned by the configured provider and are passed to callbacks unchanged; without a provider, callbacks again receive
undefined. Request Insights can still observe a curated set of local framework operations independently, including operations that are useful to the profiler but should not be exported as telemetry.This gives the feature a smaller and more explicit contract: a completed request with a typed operation timeline. It also makes completion and live updates deterministic—each settled request is retained and published exactly once, while late background work is ignored.
Verification
pnpm build-allpnpm exec jest packages/next/src/server/lib/trace/request-insights.test.ts packages/next/src/server/lib/trace/tracer.test.ts packages/next/src/server/lib/patch-fetch.test.ts --runInBandNEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-turbo test/development/app-dir/request-insights/request-insights.test.tsNEXT_TEST_PREFER_OFFLINE=1 pnpm test-dev-webpack test/development/app-dir/request-insights/request-insights.test.tsNEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-webpack test/e2e/app-dir/app/standalone.test.ts