Fix Request Insights production tracing (#96000)
## Summary
I changed how the shared tracer accesses Request Insights from loading
the facade with a literal `require()` to reading the runtime already
registered globally by the development server. This prevents
`request-insights.js` and `request-insights-runtime.js` from appearing
in production NFT output, while keeping Request Insights behavior in
development unchanged.
I also changed the `expect.any(Function)` matcher to an existence
matcher plus an explicit `typeof` assertion so the repository's
banned-function-call checker passes without weakening the test.
This PR is stacked on #95897.
## Before: Tracer Owns Loading
- Production-used tracer
- Literal `require()`
- Request-insights facade
- Request-insights runtime
- NFT includes development modules
## After: Dev Server Owns Loading
- `next-dev-server` registers the runtime
- Global `Symbol` slot
- Tracer performs an optional lookup
- No runtime module import
- NFT excludes development modules
```js
// The production-used tracer now performs a lookup, not a load.
if (process.env.__NEXT_DEV_SERVER) {
return globalThis[
Symbol.for('@next/request-insights-runtime')
]
}
```
## Verification
- `pnpm exec jest packages/next/src/server/lib/trace/tracer.test.ts
packages/next/src/server/lib/trace/request-insights.test.ts
--runInBand`
- `pnpm --filter=next typescript`
- `pnpm --filter=next types`
- `HEADLESS=true IS_TURBOPACK_TEST=1 TURBOPACK_BUILD=1
NEXT_TEST_MODE=start pnpm test-start-turbo
test/production/next-server-nft/
next-server-nft.test.ts`
- `HEADLESS=true pnpm test-dev-turbo
test/development/app-dir/request-insights/request-insights.test.ts`
- `HEADLESS=true pnpm test-start-webpack
test/e2e/app-dir/app/standalone.test.ts`
- `pnpm --filter=next build`
<!-- NEXT_JS_LLM -->
Showing
Please
register
or
sign in
to comment