Unverified Commit d98b5a57 authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Tracing: attach Turbopack session value to root span (#60576)

This allows us to more accurately attribute whether a trace was created
in a Turbopack session by doing so at trace creation time rather than
trace upload time.

Test Plan: Configured next to send traces to a local server and verified
this information is attached to the top-level of the trace.


Closes PACK-2233
parent 3da48113
...@@ -95,7 +95,6 @@ const handleSessionStop = async (signal: string | null) => { ...@@ -95,7 +95,6 @@ const handleSessionStop = async (signal: string | null) => {
uploadTrace({ uploadTrace({
traceUploadUrl, traceUploadUrl,
mode: 'dev', mode: 'dev',
isTurboSession,
projectDir: dir, projectDir: dir,
distDir: config.distDir, distDir: config.distDir,
}) })
...@@ -283,7 +282,6 @@ const nextDev: CliCommand = async (args) => { ...@@ -283,7 +282,6 @@ const nextDev: CliCommand = async (args) => {
uploadTrace({ uploadTrace({
traceUploadUrl, traceUploadUrl,
mode: 'dev', mode: 'dev',
isTurboSession,
projectDir: dir, projectDir: dir,
distDir: config.distDir, distDir: config.distDir,
sync: true, sync: true,
......
...@@ -35,9 +35,7 @@ const { ...@@ -35,9 +35,7 @@ const {
const isDebugEnabled = !!NEXT_TRACE_UPLOAD_DEBUG || !!NEXT_TRACE_UPLOAD_FULL const isDebugEnabled = !!NEXT_TRACE_UPLOAD_DEBUG || !!NEXT_TRACE_UPLOAD_FULL
const shouldUploadFullTrace = !!NEXT_TRACE_UPLOAD_FULL const shouldUploadFullTrace = !!NEXT_TRACE_UPLOAD_FULL
const [, , traceUploadUrl, mode, _isTurboSession, projectDir, distDir] = const [, , traceUploadUrl, mode, projectDir, distDir] = process.argv
process.argv
const isTurboSession = _isTurboSession === 'true'
type TraceRequestBody = { type TraceRequestBody = {
metadata: TraceMetadata metadata: TraceMetadata
...@@ -100,6 +98,7 @@ interface TraceMetadata { ...@@ -100,6 +98,7 @@ interface TraceMetadata {
crlfDelay: Infinity, crlfDelay: Infinity,
}) })
let isTurboSession = false
const traces = new Map<string, TraceEvent[]>() const traces = new Map<string, TraceEvent[]>()
for await (const line of readLineInterface) { for await (const line of readLineInterface) {
const lineEvents: TraceEvent[] = JSON.parse(line) const lineEvents: TraceEvent[] = JSON.parse(line)
...@@ -115,6 +114,9 @@ interface TraceMetadata { ...@@ -115,6 +114,9 @@ interface TraceMetadata {
trace = [] trace = []
traces.set(event.traceId, trace) traces.set(event.traceId, trace)
} }
if (typeof event.tags.isTurbopack === 'boolean') {
isTurboSession = event.tags.isTurbopack
}
trace.push(event) trace.push(event)
} }
} }
......
...@@ -47,6 +47,11 @@ export class Span { ...@@ -47,6 +47,11 @@ export class Span {
this.name = name this.name = name
this.parentId = parentId ?? defaultParentSpanId this.parentId = parentId ?? defaultParentSpanId
this.attrs = attrs ? { ...attrs } : {} this.attrs = attrs ? { ...attrs } : {}
if (this.parentId === undefined) {
// Attach additional information to root spans
this.attrs.isTurbopack = Boolean(process.env.TURBOPACK)
}
this.status = SpanStatus.Started this.status = SpanStatus.Started
this.id = getId() this.id = getId()
this._start = startTime || process.hrtime.bigint() this._start = startTime || process.hrtime.bigint()
......
export default function uploadTrace({ export default function uploadTrace({
traceUploadUrl, traceUploadUrl,
mode, mode,
isTurboSession,
projectDir, projectDir,
distDir, distDir,
sync, sync,
}: { }: {
traceUploadUrl: string traceUploadUrl: string
mode: 'dev' mode: 'dev'
isTurboSession: boolean
projectDir: string projectDir: string
distDir: string distDir: string
sync?: boolean sync?: boolean
...@@ -33,7 +31,6 @@ export default function uploadTrace({ ...@@ -33,7 +31,6 @@ export default function uploadTrace({
require.resolve('./trace-uploader'), require.resolve('./trace-uploader'),
traceUploadUrl, traceUploadUrl,
mode, mode,
String(isTurboSession),
projectDir, projectDir,
distDir, distDir,
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment