Skip to content

fix: await ensureInstrumentationRegistered in RouteModule.prepare#94069

Draft
hammadxcm wants to merge 1 commit into
vercel:canaryfrom
hammadxcm:fix/route-module-await-instrumentation
Draft

fix: await ensureInstrumentationRegistered in RouteModule.prepare#94069
hammadxcm wants to merge 1 commit into
vercel:canaryfrom
hammadxcm:fix/route-module-await-instrumentation

Conversation

@hammadxcm
Copy link
Copy Markdown

What?

RouteModule.prepare() called ensureInstrumentationRegistered() without awaiting it, then proceeded to load manifests and handle the request. This adds the missing await.

Why?

The function is async and registers the instrumentation hook (including onRequestError). Without awaiting, request handling can begin before registration completes, so early request errors may not reach onRequestError. Every other call site already awaits it — next-server.ts, next-dev-server.ts, and web/adapter.ts — so this was the only inconsistent path. The inline comment ("ensure instrumentation is registered and pass onRequestError below") confirms the intent was to complete registration first.

How?

Add await to the call in route-module.ts. ensureInstrumentationRegistered() memoizes its promise (registerInstrumentationPromise), so after the first request this awaits an already-resolved promise — effectively free.

Verification

  • pnpm --filter=next build
  • pnpm --filter=next types
  • pnpm prettier --write + eslint --fix on the changed file (clean)
  • pnpm test-dev-turbo test/e2e/instrumentation-hook/instrumentation-hook.test.ts (9 passed, 1 skipped)
  • pnpm test-dev-turbo test/e2e/app-dir/instrumentation-order (passed)
  • Not adding a dedicated unit test: the change fixes a registration race that is not feasible to assert deterministically. Coverage is via the existing instrumentation e2e suites above, and the change makes this call site consistent with every other one.

Fixes #93993

RouteModule.prepare() called ensureInstrumentationRegistered() without
awaiting it before proceeding to load manifests and handle the request,
so request handling could begin before the instrumentation hook (and its
onRequestError) finished registering. Every other call site awaits it
(next-server.ts, next-dev-server.ts, web/adapter.ts); this aligns the
route-module path with them. The call memoizes its promise, so awaiting
is effectively free after the first request.
@hammadxcm hammadxcm force-pushed the fix/route-module-await-instrumentation branch from 066f423 to de2f901 Compare May 23, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RouteModule.prepare doesn't await ensureInstrumentationRegistered

1 participant