Unverified Commit 51797dbd authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Trace upload: add git and environment info (#91124)

This adds the following to uploaded trace data:

- Git branch/ref name
- Whether the trace was uploaded from a Vercel environment
- Prefers Vercel git environment variable data over running git

Test Plan: Ran a manual test app with EXPERIMENTAL_FLAGS_DEBUG=1, set
the corresponding environment variables and confirmed they were
reflected
parent bfb8cc7a
...@@ -99,8 +99,10 @@ interface TraceEvent { ...@@ -99,8 +99,10 @@ interface TraceEvent {
interface TraceMetadata { interface TraceMetadata {
anonymousId: string anonymousId: string
arch: string arch: string
branch: string
commit: string commit: string
cpus: number cpus: number
isVercelEnvironment: boolean
isTurboSession: boolean isTurboSession: boolean
mode: string mode: string
nextVersion: string nextVersion: string
...@@ -126,14 +128,23 @@ interface TraceMetadata { ...@@ -126,14 +128,23 @@ interface TraceMetadata {
) )
const pkgName = projectPkgJson.name const pkgName = projectPkgJson.name
const commit = child_process const git = os.platform() === 'win32' ? 'git.exe' : 'git'
.spawnSync(
os.platform() === 'win32' ? 'git.exe' : 'git', const isVercelEnvironment = !!process.env.VERCEL
['rev-parse', 'HEAD'],
{ shell: true } const commit =
) process.env.VERCEL_GIT_COMMIT_SHA ||
.stdout.toString() child_process
.trimEnd() .spawnSync(git, ['rev-parse', 'HEAD'])
.stdout.toString()
.trimEnd()
const branch =
process.env.VERCEL_GIT_COMMIT_REF ||
child_process
.spawnSync(git, ['rev-parse', '--abbrev-ref', 'HEAD'])
.stdout.toString()
.trimEnd()
const readLineInterface = createInterface({ const readLineInterface = createInterface({
input: createReadStream(path.join(projectDir, distDir, 'trace')), input: createReadStream(path.join(projectDir, distDir, 'trace')),
...@@ -207,8 +218,10 @@ interface TraceMetadata { ...@@ -207,8 +218,10 @@ interface TraceMetadata {
metadata: { metadata: {
anonymousId, anonymousId,
arch: os.arch(), arch: os.arch(),
branch,
commit, commit,
cpus: os.cpus().length, cpus: os.cpus().length,
isVercelEnvironment,
isTurboSession, isTurboSession,
mode, mode,
nextVersion, nextVersion,
......
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