next.js
682b03f7 - Trace lazy App Route module loading (#97439)

Commit
16 days ago
Trace lazy App Route module loading (#97439) ### What? Adds a public OpenTelemetry span for the cold evaluation of an App Route's lazy userland module: - span type: `AppRouteRouteModule.loadUserland` - display name: `load app route module` - route-specific attribute: the normalized `next.route` pattern ### Why? `LoadComponents.loadRouteModule` measures loading Next.js's compiled route entry. App Routes then defer the actual userland module behind a `LazyModule`, so expensive top-level module evaluation can occur after that existing span has ended and remain invisible in traces. ### How? The App Route module wraps only its lazy userland factory with the Next.js tracer. `LazyModule` still memoizes that factory, so each route-module instance emits one span for its successful cold initialization and warm requests reuse the initialized value. The HMR getter remains untraced, and the span records no resolved filename or request URL. The integration fixture uses top-level await to exercise the asynchronous module path. Coverage verifies the span is a descendant of the request, appears exactly once across cold and warm requests, and works with the direct entrypoint handler. ### Verification - `pnpm exec jest packages/next/src/server/lib/trace/tracer.test.ts --runInBand` - `HEADLESS=true pnpm test-dev-turbo test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts -t 'should trace cold App Route module loading'` - `HEADLESS=true pnpm test-dev-webpack test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts -t 'should trace cold App Route module loading'` - `HEADLESS=true pnpm test-start-turbo test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts -t 'should trace cold App Route module loading'` - `HEADLESS=true pnpm test-start-webpack test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts -t 'should trace cold App Route module loading'` - Exact-head GitHub build-and-test run `31950299347`: 102/102 jobs passed. - Exact-head Generate Stats run `31950299340`: passed.
Author
Parents
Loading