[.next/trace] Record start-dev-server trace span (#58469)

This PR makes sure that the `start-dev-server` trace span is recorded to the `.next/trace` file and uploaded to the telemetry endpoint when opted in. 

Before this PR, the `start-dev-server` span was recorded in `next-dev` in the CLI. However, this would never be written to the `.next/trace` file since it happens in a different process (not the child process for next server). After this PR, the trace span happens in the next-server child process and will be recorded in the `.next/trace` file along with the other events produced by the dev server.
This commit is contained in:
mknichel 2023-11-16 13:36:00 -08:00 committed by GitHub
parent 97ba91097d
commit 3ac27117c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View file

@ -27,7 +27,6 @@ import { createSelfSignedCertificate } from '../lib/mkcert'
import type { SelfSignedCertificate } from '../lib/mkcert'
import uploadTrace from '../trace/upload-trace'
import { initialEnv } from '@next/env'
import { trace } from '../trace'
import { fork } from 'child_process'
import {
getReservedPortExplanation,
@ -318,9 +317,7 @@ const nextDev: CliCommand = async (args) => {
}
}
await trace('start-dev-server').traceAsyncFn(async (_) => {
await runDevServer(false)
})
await runDevServer(false)
}
function cleanup() {

View file

@ -22,6 +22,7 @@ import { initialize } from './router-server'
import { CONFIG_FILES } from '../../shared/lib/constants'
import { getStartServerInfo, logStartInfo } from './app-info-log'
import { validateTurboNextConfig } from '../../lib/turbopack-warning'
import { trace } from '../../trace'
import { isPostpone } from './router-utils/is-postpone'
const debug = setupDebug('next:start-server')
@ -361,7 +362,9 @@ export async function startServer(
if (process.env.NEXT_PRIVATE_WORKER && process.send) {
process.addListener('message', async (msg: any) => {
if (msg && typeof msg && msg.nextWorkerOptions && process.send) {
await startServer(msg.nextWorkerOptions)
await trace('start-dev-server').traceAsyncFn(() =>
startServer(msg.nextWorkerOptions)
)
process.send({ nextServerReady: true })
}
})

View file

@ -18,6 +18,7 @@ const EVENT_FILTER = new Set([
'webpack-invalid-client',
'webpack-invalidated-server',
'navigation-to-hydration',
'start-dev-server',
])
const {