Unverified Commit 6e77c071 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Update Next.js Telemetry Event Shapes (#8628)

* Update Next.js Telemetry Event Shapes

* Force value as-is
parent 61b8b732
......@@ -64,7 +64,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
await verifyTypeScriptSetup(dir)
let backgroundWork: (Promise<any> | undefined)[] = []
backgroundWork.push(recordVersion(), recordNextPlugins(path.resolve(dir)))
backgroundWork.push(
recordVersion({ cliCommand: 'build' }),
recordNextPlugins(path.resolve(dir))
)
console.log('Creating an optimized production build ...')
console.log()
......@@ -199,7 +202,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
console.log(chalk.green('Compiled successfully.\n'))
backgroundWork.push(
recordBuildDuration({
numberOfPages: allPagePaths.length,
totalPageCount: allPagePaths.length,
durationInSeconds: webpackBuildEnd[0],
})
)
......@@ -410,7 +413,8 @@ export default async function build(dir: string, conf = null): Promise<void> {
recordBuildOptimize({
durationInSeconds: analysisEnd[0],
totalPageCount: allPagePaths.length,
staticOptimizedPages: staticPages.size,
staticPageCount: staticPages.size,
ssrPageCount: allPagePaths.length - staticPages.size,
})
)
......
......@@ -179,7 +179,7 @@ export default class DevServer extends Server {
await this.startWatcher()
this.setDevReady()
recordVersion({ isDev: true })
recordVersion({ cliCommand: 'dev' })
}
async close () {
......
import { record } from '../storage'
const EVENT_BUILD_DURATION = 'NEXT_BUILD_DURATION'
type BuildDurationEventShape = {
const EVENT_BUILD_DURATION = 'NEXT_BUILD_COMPLETED'
type EventBuildCompleted = {
durationInSeconds: number
numberOfPages: number
totalPageCount: number
}
export function recordBuildDuration(event: BuildDurationEventShape) {
export function recordBuildDuration(event: EventBuildCompleted) {
return record({
eventName: EVENT_BUILD_DURATION,
payload: {
seconds: event.durationInSeconds,
pageCount: event.numberOfPages,
},
payload: event,
})
}
const EVENT_BUILD_OPTIMIZE = 'NEXT_BUILD_OPTIMIZE'
type BuildAnalysisEventShape = {
const EVENT_BUILD_OPTIMIZE = 'NEXT_BUILD_OPTIMIZED'
type EventBuildOptimized = {
durationInSeconds: number
totalPageCount: number
staticOptimizedPages: number
staticPageCount: number
ssrPageCount: number
}
export function recordBuildOptimize(event: BuildAnalysisEventShape) {
export function recordBuildOptimize(event: EventBuildOptimized) {
return record({
eventName: EVENT_BUILD_OPTIMIZE,
payload: {
seconds: event.durationInSeconds,
pageCount: event.totalPageCount,
pageAutomaticPrerenderedCount: event.staticOptimizedPages,
},
payload: event,
})
}
import { record } from '../storage'
import findUp from 'find-up'
const EVENT_PLUGIN_PRESENT = 'NEXT_PLUGIN_PRESENT'
type PluginPresentEventShape = {
pluginName: string
pluginVersion: string
const EVENT_PLUGIN_PRESENT = 'NEXT_PACKAGE_DETECTED'
type EventPackageDetected = {
packageName: string
packageVersion: string
}
const plugins = [
......@@ -177,9 +177,9 @@ export async function recordNextPlugins(dir: string) {
}[]).map(({ pluginName, pluginVersion }) => ({
eventName: EVENT_PLUGIN_PRESENT,
payload: {
pluginName,
pluginVersion,
} as PluginPresentEventShape,
packageName: pluginName,
packageVersion: pluginVersion,
} as EventPackageDetected,
}))
)
} catch (_) {}
......
import { record } from '../storage'
const EVENT_VERSION = 'NEXT_VERSION'
const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED'
export function recordVersion({ isDev = false } = {}) {
type EventCliSessionStarted = {
nextVersion: string
nodeVersion: string
cliCommand: string
}
export function recordVersion(
event: Omit<EventCliSessionStarted, 'nextVersion' | 'nodeVersion'>
) {
// This should be an invariant, if it fails our build tooling is broken.
if (typeof process.env.__NEXT_VERSION !== 'string') {
return Promise.resolve()
......@@ -11,9 +19,9 @@ export function recordVersion({ isDev = false } = {}) {
return record({
eventName: EVENT_VERSION,
payload: {
version: process.env.__NEXT_VERSION,
nextVersion: process.env.__NEXT_VERSION,
nodeVersion: process.version,
isDevelopment: isDev,
},
cliCommand: event.cliCommand,
} as EventCliSessionStarted,
})
}
......@@ -148,7 +148,15 @@ export function isTelemetryEnabled(): boolean {
}
type TelemetryEvent = { eventName: string; payload: object }
type EventContext = {
anonymousId: string
projectId: string
sessionId: string
}
type EventBatchShape = {
eventName: string
fields: object
}
function _record(_events: TelemetryEvent | TelemetryEvent[]): Promise<any> {
let events: TelemetryEvent[]
if (Array.isArray(_events)) {
......@@ -185,14 +193,17 @@ function _record(_events: TelemetryEvent | TelemetryEvent[]): Promise<any> {
return Promise.resolve()
}
const context = { anonymousProjectId: projectId, runId: randomRunId }
const context: EventContext = {
anonymousId: anonymousId,
projectId: projectId!,
sessionId: randomRunId!,
}
return _postPayload(`https://telemetry.nextjs.org/api/v1/record`, {
anonymousId,
context,
events: events.map(({ eventName, payload }) => ({
eventName,
fields: payload,
})),
})) as Array<EventBatchShape>,
})
}
......
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