diff --git a/packages/next/src/trace/trace-uploader.ts b/packages/next/src/trace/trace-uploader.ts index 8634ca41965393..5fe90217871fd0 100644 --- a/packages/next/src/trace/trace-uploader.ts +++ b/packages/next/src/trace/trace-uploader.ts @@ -9,6 +9,9 @@ import { createInterface } from 'readline' import { createReadStream } from 'fs' import path from 'path' +// Predefined set of the event names to be included in the trace. +// If the trace span's name matches to one of the event names in the set, +// it'll up uploaded to the trace server. const EVENT_FILTER = new Set([ 'client-hmr-latency', 'hot-reloader', @@ -16,7 +19,16 @@ const EVENT_FILTER = new Set([ 'webpack-invalidated-server', ]) -const { NEXT_TRACE_UPLOAD_DEBUG } = process.env +const { + NEXT_TRACE_UPLOAD_DEBUG, + // An external env to allow to upload full trace without picking up the relavant spans. + // This is mainly for the debugging purpose, to allwo manual audit for full trace for the given build. + // [NOTE] This may fail if build is large and generated trace is excessively large. + NEXT_TRACE_UPLOAD_FULL, +} = process.env + +const isDebugEnabled = !!NEXT_TRACE_UPLOAD_DEBUG || !!NEXT_TRACE_UPLOAD_FULL +const shouldUploadFullTrace = !!NEXT_TRACE_UPLOAD_FULL const [, , traceUploadUrl, mode, _isTurboSession, projectDir, distDir] = process.argv @@ -78,6 +90,7 @@ interface TraceMetadata { if ( // Always include root spans event.parentId === undefined || + shouldUploadFullTrace || EVENT_FILTER.has(event.name) ) { if ( @@ -114,7 +127,7 @@ interface TraceMetadata { traces: [...traces.values()], } - if (NEXT_TRACE_UPLOAD_DEBUG) { + if (isDebugEnabled) { console.log('Sending request with body', JSON.stringify(body, null, 2)) } @@ -126,7 +139,7 @@ interface TraceMetadata { body: JSON.stringify(body), }) - if (NEXT_TRACE_UPLOAD_DEBUG) { + if (isDebugEnabled) { console.log('Received response', res.status, await res.json()) } })()