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

Debug tracing: include session and anonymous ids #55021

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion packages/next/src/telemetry/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ function getStorageDirectory(distDir: string): string | undefined {
}

export class Telemetry {
readonly sessionId: string

private conf: Conf<any> | null
private distDir: string
private sessionId: string
private loadProjectId: undefined | string | Promise<string>
private NEXT_TELEMETRY_DISABLED: any
private NEXT_TELEMETRY_DEBUG: any
Expand Down
11 changes: 9 additions & 2 deletions packages/next/src/trace/trace-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import os from 'os'
import { createInterface } from 'readline'
import { createReadStream } from 'fs'
import path from 'path'
import { Telemetry } from '../telemetry/storage'

// 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,
Expand Down Expand Up @@ -52,14 +53,16 @@ interface TraceEvent {
}

interface TraceMetadata {
anonymousId: string
arch: string
commit: string
cpus: number
isTurboSession: boolean
mode: string
nextVersion: string
pkgName: string
platform: string
isTurboSession: boolean
nextVersion: string
sessionId: string
}

;(async function upload() {
Expand All @@ -70,6 +73,8 @@ interface TraceMetadata {
)
).version

const telemetry = new Telemetry({ distDir })

const projectPkgJsonPath = await findUp('package.json')
assert(projectPkgJsonPath)

Expand Down Expand Up @@ -125,6 +130,7 @@ interface TraceMetadata {

const body: TraceRequestBody = {
metadata: {
anonymousId: telemetry.anonymousId,
arch: os.arch(),
commit,
cpus: os.cpus().length,
Expand All @@ -133,6 +139,7 @@ interface TraceMetadata {
nextVersion,
pkgName,
platform: os.platform(),
sessionId: telemetry.sessionId,
},
traces: [...traces.values()],
}
Expand Down