Skip to content

Commit

Permalink
Debug tracing: include session and anonymous ids (#55021)
Browse files Browse the repository at this point in the history
This adds session ids and anonymous ids to trace metadata.

Note: This required setting `session`id on the `Telemetry` object as a public property. Set as readonly.


Closes WEB-1500
  • Loading branch information
wbinnssmith authored Sep 6, 2023
1 parent 1f797fa commit 45538e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit 45538e9

Please sign in to comment.