Unverified Commit 36c14da3 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

ci(trace): allow to opt in to upload full trace (#54347)



### What?
 
Came to realize it might be useful to upload full trace. This is avoided by default as trace might grow excessively, however might be useful to audit individual trace if it can be uploaded.

Closes WEB-1416
parent 3370022a
......@@ -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))
}
......@@ -122,11 +135,12 @@ interface TraceMetadata {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-trace-transfer-mode': shouldUploadFullTrace ? 'full' : 'default',
},
body: JSON.stringify(body),
})
if (NEXT_TRACE_UPLOAD_DEBUG) {
if (isDebugEnabled) {
console.log('Received response', res.status, await res.json())
}
})()
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