Skip to content

Commit

Permalink
ci(trace): allow to opt in to upload full trace
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Aug 21, 2023
1 parent b7eb6d4 commit 652b55b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/next/src/trace/trace-uploader.ts
Expand Up @@ -9,14 +9,26 @@ 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',
'webpack-invalid-client',
'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
Expand Down Expand Up @@ -78,6 +90,7 @@ interface TraceMetadata {
if (
// Always include root spans
event.parentId === undefined ||
shouldUploadFullTrace ||
EVENT_FILTER.has(event.name)
) {
if (
Expand Down Expand Up @@ -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))
}

Expand All @@ -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())
}
})()

0 comments on commit 652b55b

Please sign in to comment.