fix: call instrumentationHook earlier for prod server (#63536)

This ensures that the instrumentation hook for Node.js will run
immediately during `next start` instead of waiting for the first request
like does it `next dev`.

However, if there is a separate instrumentation hook for Edge, that will
still be lazy evaluated and wait until the first request.

Fixes #59999 
Fixes NEXT-2738
This commit is contained in:
Steven
2024-03-21 13:11:03 +00:00
committed by GitHub
parent 39340ab424
commit abe74a5211
2 changed files with 10 additions and 2 deletions
+10
View File
@@ -252,6 +252,16 @@ export default class NextNodeServer extends BaseServer {
}
this.middlewareManifestPath = join(this.serverDistDir, MIDDLEWARE_MANIFEST)
// This is just optimization to fire prepare as soon as possible. It will be
// properly awaited later. We add the catch here to ensure that it does not
// cause a unhandled promise rejection. The promise rejection will be
// handled later on via the `await` when the request handler is called.
if (!options.dev) {
this.prepare().catch((err) => {
console.error('Failed to prepare server', err)
})
}
}
protected async handleUpgrade(): Promise<void> {
@@ -67,14 +67,12 @@ describe('Instrumentation Hook', () => {
describeCase('with-node-api', ({ next }) => {
it('with-node-api should run the instrumentation hook', async () => {
await next.render('/api')
await check(() => next.cliOutput, /instrumentation hook on nodejs/)
})
})
describeCase('with-node-page', ({ next }) => {
it('with-node-page should run the instrumentation hook', async () => {
await next.render('/')
await check(() => next.cliOutput, /instrumentation hook on nodejs/)
})
})