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

Add relationship between issuer and module to traces #28192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 12 additions & 21 deletions packages/next/build/compiler.ts
@@ -1,4 +1,5 @@
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { Span } from '../telemetry/trace'

export type CompilerResult = {
errors: string[]
Expand Down Expand Up @@ -35,16 +36,16 @@ function closeCompiler(compiler: webpack.Compiler | webpack.MultiCompiler) {
}

export function runCompiler(
config: webpack.Configuration | webpack.Configuration[]
config: webpack.Configuration,
{ runWebpackSpan }: { runWebpackSpan: Span }
): Promise<CompilerResult> {
return new Promise((resolve, reject) => {
const compiler = webpack(config)
compiler.run(
(
err: Error,
statsOrMultiStats: { stats: webpack.Stats[] } | webpack.Stats
) => {
closeCompiler(compiler).then(() => {
compiler.run((err: Error, stats: webpack.Stats) => {
const webpackCloseSpan = runWebpackSpan.traceChild('webpack-close')
webpackCloseSpan
.traceAsyncFn(() => closeCompiler(compiler))
.then(() => {
if (err) {
const reason = err?.toString()
if (reason) {
Expand All @@ -53,21 +54,11 @@ export function runCompiler(
return reject(err)
}

if ('stats' in statsOrMultiStats) {
const result: CompilerResult = statsOrMultiStats.stats.reduce(
generateStats,
{ errors: [], warnings: [] }
)
return resolve(result)
}

const result = generateStats(
{ errors: [], warnings: [] },
statsOrMultiStats
)
const result = webpackCloseSpan
.traceChild('webpack-generate-error-stats')
.traceFn(() => generateStats({ errors: [], warnings: [] }, stats))
return resolve(result)
})
}
)
})
})
}
4 changes: 2 additions & 2 deletions packages/next/build/index.ts
Expand Up @@ -570,15 +570,15 @@ export default async function build(
let result: CompilerResult = { warnings: [], errors: [] }
// We run client and server compilation separately to optimize for memory usage
await runWebpackSpan.traceAsyncFn(async () => {
const clientResult = await runCompiler(clientConfig)
const clientResult = await runCompiler(clientConfig, { runWebpackSpan })
// Fail build if clientResult contains errors
if (clientResult.errors.length > 0) {
result = {
warnings: [...clientResult.warnings],
errors: [...clientResult.errors],
}
} else {
const serverResult = await runCompiler(configs[1])
const serverResult = await runCompiler(configs[1], { runWebpackSpan })
result = {
warnings: [...clientResult.warnings, ...serverResult.warnings],
errors: [...clientResult.errors, ...serverResult.errors],
Expand Down
1 change: 1 addition & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -860,6 +860,7 @@ export default async function getBaseWebpackConfig(
const emacsLockfilePattern = '**/.#*'

let webpackConfig: webpack.Configuration = {
parallelism: Number(process.env.NEXT_WEBPACK_PARALLELISM) || undefined,
externals: !isServer
? // make sure importing "next" is handled gracefully for client
// bundles in case a user imported types and it wasn't removed
Expand Down
4 changes: 3 additions & 1 deletion packages/next/build/webpack/plugins/profiling-plugin.ts
Expand Up @@ -101,9 +101,11 @@ export class ProfilingPlugin {
return module.userRequest.split('.').pop()
})()

const issuerModule = compilation?.moduleGraph?.getIssuer(module)

const span = trace(
`build-module${moduleType ? `-${moduleType}` : ''}`,
compilerSpan.id
issuerModule ? spans.get(issuerModule)?.id : compilerSpan.id
)
span.setAttribute('name', module.userRequest)
spans.set(module, span)
Expand Down