Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with instrumentation in a standalone build #48615

Merged
merged 5 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,8 @@ export default async function build(
denormalizedAppPages,
outputFileTracingRoot,
requiredServerFiles.config,
middlewareManifest
middlewareManifest,
Boolean(config.experimental.instrumentationHook)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was looking at this yesterday I was thinking you want to pass hasInstrumentationHook (i.e. whether the file exists), not the config value here. Otherwise it will probably crash if the flag is enabled but no instrumentation set up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I get for not writing proper tests.
Thanks for finding this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed now.

)
})
}
Expand Down
11 changes: 10 additions & 1 deletion packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,8 @@ export async function copyTracedFiles(
appPageKeys: readonly string[] | undefined,
tracingRoot: string,
serverConfig: { [key: string]: any },
middlewareManifest: MiddlewareManifest
middlewareManifest: MiddlewareManifest,
instrumentationHook: boolean
) {
const outputPath = path.join(distDir, 'standalone')
let moduleType = false
Expand Down Expand Up @@ -1896,6 +1897,7 @@ export async function copyTracedFiles(
Log.warn(`Failed to copy traced files for ${pageFile}`, err)
})
}

if (appPageKeys) {
for (const page of appPageKeys) {
if (middlewareManifest.functions.hasOwnProperty(page)) {
Expand All @@ -1908,6 +1910,13 @@ export async function copyTracedFiles(
})
}
}

if (instrumentationHook) {
await handleTraceFiles(
path.join(distDir, 'server', 'instrumentation.js.nft.json')
)
}

await handleTraceFiles(path.join(distDir, 'next-server.js.nft.json'))
const serverOutputPath = path.join(
outputPath,
Expand Down