Skip to content

Commit bb75506

Browse files
authored
Turbopack: Add --internal-trace cli flag (#92190)
## What? Adds `--internal-trace` to both `dev` and `build` that enables `NEXT_TURBOPACK_TRACING=turbo-tasks`. Optionally supports `minimal` and `all` (all is the default). When `minimal` is provided it passes `NEXT_TURBOPACK_TRACING=1` and the trace file won't include turbo-tasks spans.
1 parent 893198c commit bb75506

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

packages/next/src/bin/next.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ program
208208
'--experimental-cpu-prof',
209209
'Enable CPU profiling. Profile is saved to .next-profiles/ on exit.'
210210
)
211+
.addOption(
212+
new Option(
213+
'--internal-trace [level]',
214+
'Enable Turbopack tracing. "all" (default) enables turbo-tasks level tracing, "overview" enables overview tracing.'
215+
)
216+
.choices(['all', 'overview'])
217+
.preset('all')
218+
)
211219
.action((directory: string, options: NextBuildOptions) => {
212220
if (options.debugPrerender) {
213221
// @ts-expect-error not readonly
@@ -225,6 +233,12 @@ program
225233
mkdirSync(cpuProfileDir, { recursive: true })
226234
process.env.NEXT_CPU_PROF_DIR = cpuProfileDir
227235
}
236+
if (options.internalTrace) {
237+
process.env.NEXT_TURBOPACK_TRACING =
238+
options.internalTrace === 'all'
239+
? 'turbo-tasks'
240+
: String(options.internalTrace)
241+
}
228242

229243
// ensure process exits after build completes so open handles/connections
230244
// don't cause process to hang
@@ -350,6 +364,14 @@ program
350364
'--experimental-cpu-prof',
351365
'Enable CPU profiling. Profiles are saved to .next-profiles/ on exit.'
352366
)
367+
.addOption(
368+
new Option(
369+
'--internal-trace [level]',
370+
'Enable Turbopack tracing. "all" (default) enables turbo-tasks level tracing, "overview" enables overview tracing.'
371+
)
372+
.choices(['all', 'overview'])
373+
.preset('all')
374+
)
353375
.action(
354376
(directory: string, options: NextDevOptions, { _optionValueSources }) => {
355377
if (options.experimentalNextConfigStripTypes) {
@@ -364,6 +386,12 @@ program
364386
mkdirSync(cpuProfileDir, { recursive: true })
365387
process.env.NEXT_CPU_PROF_DIR = cpuProfileDir
366388
}
389+
if (options.internalTrace) {
390+
process.env.NEXT_TURBOPACK_TRACING =
391+
options.internalTrace === 'all'
392+
? 'turbo-tasks'
393+
: String(options.internalTrace)
394+
}
367395
const portSource = _optionValueSources.port
368396
import('../cli/next-dev.js').then((mod) =>
369397
mod.nextDev(options, portSource, directory)

packages/next/src/cli/next-build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type NextBuildOptions = {
3333
experimentalNextConfigStripTypes?: boolean
3434
debugBuildPaths?: string
3535
experimentalCpuProf?: boolean
36+
internalTrace?: string | boolean
3637
}
3738

3839
const nextBuild = async (options: NextBuildOptions, directory?: string) => {

packages/next/src/cli/next-dev.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type NextDevOptions = {
5656
experimentalNextConfigStripTypes?: boolean
5757
experimentalCpuProf?: boolean
5858
serverFastRefresh?: boolean
59+
internalTrace?: string | boolean
5960
}
6061

6162
type PortSource = 'cli' | 'default' | 'env'
@@ -348,6 +349,9 @@ const nextDev = async (
348349
__NEXT_PRIVATE_CPU_PROFILE: 'dev-server',
349350
}
350351
: undefined),
352+
...(process.env.NEXT_TURBOPACK_TRACING
353+
? { NEXT_TURBOPACK_TRACING: process.env.NEXT_TURBOPACK_TRACING }
354+
: undefined),
351355
},
352356
})
353357

0 commit comments

Comments
 (0)