Skip to content

Commit

Permalink
Turbopack hmr: record forwarded client spans
Browse files Browse the repository at this point in the history
This forwards spans created in the hmr client to the server-side tracer.

Test Plan: Loaded a page and verified navigation-to-hydration span is recorded.
  • Loading branch information
wbinnssmith committed Jan 11, 2024
1 parent ca5bc98 commit b2b43e3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/next/src/server/lib/router-utils/setup-dev-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ import { bold, green, red } from '../../../lib/picocolors'
import { writeFileAtomic } from '../../../lib/fs/write-atomic'
import { PAGE_TYPES } from '../../../lib/page-types'
import { extractModulesFromTurbopackMessage } from './extract-modules-from-turbopack-message'
import { Span } from '../../../trace'

const MILLISECONDS_IN_NANOSECOND = 1_000_000
const wsServer = new ws.Server({ noServer: true })

type SetupOpts = {
Expand Down Expand Up @@ -1348,7 +1350,19 @@ async function startWatcher(opts: SetupOpts) {
case 'ping':
// Ping doesn't need additional handling in Turbopack.
break
case 'span-end':
case 'span-end': {
new Span({
name: parsedData.spanName,
startTime:
BigInt(Math.floor(parsedData.startTime)) *
BigInt(MILLISECONDS_IN_NANOSECOND),
attrs: parsedData.attributes,
}).stop(
BigInt(Math.floor(parsedData.endTime)) *
BigInt(MILLISECONDS_IN_NANOSECOND)
)
break
}
case 'client-error': // { errorCount, clientId }
case 'client-warning': // { warningCount, clientId }
case 'client-success': // { clientId }
Expand Down

0 comments on commit b2b43e3

Please sign in to comment.