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

Tracing: attach Turbopack session value to root span #60576

Merged
merged 1 commit into from
Jan 12, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/next/src/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const handleSessionStop = async (signal: string | null) => {
uploadTrace({
traceUploadUrl,
mode: 'dev',
isTurboSession,
projectDir: dir,
distDir: config.distDir,
})
Expand Down Expand Up @@ -283,7 +282,6 @@ const nextDev: CliCommand = async (args) => {
uploadTrace({
traceUploadUrl,
mode: 'dev',
isTurboSession,
projectDir: dir,
distDir: config.distDir,
sync: true,
Expand Down
8 changes: 5 additions & 3 deletions packages/next/src/trace/trace-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const {
const isDebugEnabled = !!NEXT_TRACE_UPLOAD_DEBUG || !!NEXT_TRACE_UPLOAD_FULL
const shouldUploadFullTrace = !!NEXT_TRACE_UPLOAD_FULL

const [, , traceUploadUrl, mode, _isTurboSession, projectDir, distDir] =
process.argv
const isTurboSession = _isTurboSession === 'true'
const [, , traceUploadUrl, mode, projectDir, distDir] = process.argv

type TraceRequestBody = {
metadata: TraceMetadata
Expand Down Expand Up @@ -100,6 +98,7 @@ interface TraceMetadata {
crlfDelay: Infinity,
})

let isTurboSession = false
const traces = new Map<string, TraceEvent[]>()
for await (const line of readLineInterface) {
const lineEvents: TraceEvent[] = JSON.parse(line)
Expand All @@ -115,6 +114,9 @@ interface TraceMetadata {
trace = []
traces.set(event.traceId, trace)
}
if (typeof event.tags.isTurbopack === 'boolean') {
isTurboSession = event.tags.isTurbopack
}
trace.push(event)
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/trace/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class Span {
this.name = name
this.parentId = parentId ?? defaultParentSpanId
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.id = getId()
this._start = startTime || process.hrtime.bigint()
Expand Down
3 changes: 0 additions & 3 deletions packages/next/src/trace/upload-trace.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
export default function uploadTrace({
traceUploadUrl,
mode,
isTurboSession,
projectDir,
distDir,
sync,
}: {
traceUploadUrl: string
mode: 'dev'
isTurboSession: boolean
projectDir: string
distDir: string
sync?: boolean
Expand All @@ -33,7 +31,6 @@ export default function uploadTrace({
require.resolve('./trace-uploader'),
traceUploadUrl,
mode,
String(isTurboSession),
projectDir,
distDir,
],
Expand Down
Loading