fix: await ensureInstrumentationRegistered in RouteModule.prepare#94069
Draft
hammadxcm wants to merge 1 commit into
Draft
fix: await ensureInstrumentationRegistered in RouteModule.prepare#94069hammadxcm wants to merge 1 commit into
hammadxcm wants to merge 1 commit into
Conversation
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.
066f423 to
de2f901
Compare
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.
What?
RouteModule.prepare()calledensureInstrumentationRegistered()withoutawaiting it, then proceeded to load manifests and handle the request. This adds the missingawait.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 reachonRequestError. Every other call site already awaits it —next-server.ts,next-dev-server.ts, andweb/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
awaitto the call inroute-module.ts.ensureInstrumentationRegistered()memoizes its promise (registerInstrumentationPromise), so after the first request this awaits an already-resolved promise — effectively free.Verification
pnpm --filter=next buildpnpm --filter=next typespnpm prettier --write+eslint --fixon 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)Fixes #93993