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

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

Merged
merged 2 commits into from Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 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,19 +127,20 @@ interface TraceMetadata {
traces: [...traces.values()],
}

if (NEXT_TRACE_UPLOAD_DEBUG) {
if (isDebugEnabled) {
console.log('Sending request with body', JSON.stringify(body, null, 2))
}

let res = await fetch(traceUploadUrl, {
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())
}
})()