track persistent caching usage (#76996)

This commit is contained in:
Jude Gao
2025-03-11 15:33:37 -07:00
committed by GitHub
parent 3e5e6dbac0
commit 8bc2a65fdd
5 changed files with 104 additions and 2 deletions
+5
View File
@@ -206,6 +206,7 @@ import {
} from '../server/lib/router-utils/build-prefetch-segment-data-route'
import { turbopackBuild } from './turbopack-build'
import { isPersistentCachingEnabled } from '../shared/lib/turbopack/utils'
import { inlineStaticEnv, populateStaticEnv } from '../lib/inline-static-env'
type Fallback = null | boolean | string
@@ -2476,6 +2477,10 @@ export default async function build(
featureName: 'experimental/ppr',
invocationCount: config.experimental.ppr ? 1 : 0,
},
{
featureName: 'turbopackPersistentCaching',
invocationCount: isPersistentCachingEnabled(config) ? 1 : 0,
},
]
telemetry.record(
features.map((feature) => {
@@ -26,7 +26,10 @@ import type { Telemetry } from '../../../telemetry/storage'
import type { IncomingMessage, ServerResponse } from 'http'
import loadJsConfig from '../../../build/load-jsconfig'
import { createValidFileMatcher } from '../find-page-file'
import { eventCliSession } from '../../../telemetry/events'
import {
EVENT_BUILD_FEATURE_USAGE,
eventCliSession,
} from '../../../telemetry/events'
import { getDefineEnv } from '../../../build/webpack/plugins/define-env-plugin'
import { getSortedRoutes } from '../../../shared/lib/router/utils'
import {
@@ -73,6 +76,7 @@ import { createEnvDefinitions } from '../experimental/create-env-definitions'
import { JsConfigPathsPlugin } from '../../../build/webpack/plugins/jsconfig-paths-plugin'
import { store as consoleStore } from '../../../build/output/store'
import {
isPersistentCachingEnabled,
ModuleBuildError,
TurbopackInternalError,
} from '../../../shared/lib/turbopack/utils'
@@ -996,6 +1000,16 @@ export async function setupDevBundler(opts: SetupOpts) {
}
)
)
// Track build features for dev server here:
opts.telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: {
featureName: 'turbopackPersistentCaching',
invocationCount: isPersistentCachingEnabled(opts.nextConfig) ? 1 : 0,
},
})
return result
}
@@ -178,6 +178,7 @@ export type EventBuildFeatureUsage = {
| 'esmExternals'
| 'webpackPlugins'
| UseCacheTrackerKey
| 'turbopackPersistentCaching'
invocationCount: number
}
export function eventBuildFeatureUsage(
@@ -0,0 +1,7 @@
module.exports = {
experimental: {
turbo: {
unstablePersistentCaching: true
}
}
}
+76 -1
View File
@@ -6,10 +6,10 @@ import {
launchApp,
nextBuild,
nextLint,
waitFor,
} from 'next-test-utils'
import fs from 'fs-extra'
import path from 'path'
const appDir = path.join(__dirname, '..')
describe('config telemetry', () => {
@@ -761,6 +761,81 @@ describe('config telemetry', () => {
})
}
)
it('emits telemetry for persistent cache in build mode', async () => {
await fs.rename(
path.join(appDir, 'next.config.persistent-cache'),
path.join(appDir, 'next.config.js')
)
try {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
try {
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'turbopackPersistentCaching',
invocationCount: 1,
})
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
}
} finally {
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.persistent-cache')
)
}
})
it('emits telemetry for persistent cache in dev mode', async () => {
await fs.rename(
path.join(appDir, 'next.config.persistent-cache'),
path.join(appDir, 'next.config.js')
)
let app
let stderr = ''
try {
app = await launchApp(appDir, await findPort(), {
env: { NEXT_TELEMETRY_DEBUG: 1 },
onStderr(msg) {
stderr += msg || ''
},
})
await waitFor(2000)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'turbopackPersistentCaching',
invocationCount: 1,
})
} catch (err) {
require('console').error('failing stderr', err)
throw err
} finally {
if (app) {
await killApp(app)
}
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.persistent-cache')
)
}
})
}
)
})