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

add telemetry events for ppr & staleTimes experimental flags #63981

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,10 @@ export default async function build(
featureName: 'optimizeFonts',
invocationCount: config.optimizeFonts ? 1 : 0,
},
{
featureName: 'experimental/ppr',
invocationCount: config.experimental.ppr ? 1 : 0,
},
]
telemetry.record(
features.map((feature) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/telemetry/events/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ export type EventBuildFeatureUsage = {
| '@next/font/local'
| 'next/font/google'
| 'next/font/local'
| 'experimental/optimizeCss'
| 'experimental/nextScriptWorkers'
| 'experimental/optimizeCss'
| 'experimental/ppr'
| 'optimizeFonts'
| 'swcLoader'
| 'swcMinify'
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/telemetry/events/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type EventCliSessionStarted = {
turboFlag: boolean
appDir: boolean | null
pagesDir: boolean | null
staticStaleTime: number | null
dynamicStaleTime: number | null
}

function hasBabelConfig(dir: string): boolean {
Expand Down Expand Up @@ -79,6 +81,8 @@ export function eventCliSession(
| 'nextConfigOutput'
| 'trailingSlashEnabled'
| 'reactStrictMode'
| 'staticStaleTime'
| 'dynamicStaleTime'
>
): { eventName: string; payload: EventCliSessionStarted }[] {
// This should be an invariant, if it fails our build tooling is broken.
Expand Down Expand Up @@ -120,6 +124,8 @@ export function eventCliSession(
turboFlag: event.turboFlag || false,
appDir: event.appDir,
pagesDir: event.pagesDir,
staticStaleTime: nextConfig.experimental.staleTimes?.static ?? null,
dynamicStaleTime: nextConfig.experimental.staleTimes?.dynamic ?? null,
}
return [{ eventName: EVENT_VERSION, payload }]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { nextTestSetup } from 'e2e-utils'
import { browserConfigWithFixedTime, fastForwardTo } from './test-utils'
import { findAllTelemetryEvents } from 'next-test-utils'

describe('app dir client cache semantics (experimental staleTimes)', () => {
describe('dynamic: 0', () => {
Expand All @@ -8,6 +9,9 @@ describe('app dir client cache semantics (experimental staleTimes)', () => {
nextConfig: {
experimental: { staleTimes: { dynamic: 0 } },
},
env: {
NEXT_TELEMETRY_DEBUG: '1',
},
})

if (isNextDev) {
Expand Down Expand Up @@ -167,6 +171,24 @@ describe('app dir client cache semantics (experimental staleTimes)', () => {
})
})
})

describe('telemetry', () => {
it('should send staleTimes feature usage event', async () => {
const events = findAllTelemetryEvents(
next.cliOutput,
'NEXT_CLI_SESSION_STARTED'
)

expect(events).toEqual(
expect.arrayContaining([
expect.objectContaining({
staticStaleTime: null,
dynamicStaleTime: 0,
}),
])
)
})
})
})

describe('static: 180', () => {
Expand All @@ -175,6 +197,9 @@ describe('app dir client cache semantics (experimental staleTimes)', () => {
nextConfig: {
experimental: { staleTimes: { static: 180 } },
},
env: {
NEXT_TELEMETRY_DEBUG: '1',
},
})

if (isNextDev) {
Expand Down Expand Up @@ -265,5 +290,22 @@ describe('app dir client cache semantics (experimental staleTimes)', () => {
expect(loadingRandomNumber).not.toBe(newLoadingNumber)
})
})

describe('telemetry', () => {
it('should send staleTimes feature usage event', async () => {
const events = findAllTelemetryEvents(
next.cliOutput,
'NEXT_CLI_SESSION_STARTED'
)
expect(events).toEqual(
expect.arrayContaining([
expect.objectContaining({
staticStaleTime: 180,
dynamicStaleTime: null,
}),
])
)
})
})
})
})
18 changes: 17 additions & 1 deletion test/e2e/app-dir/ppr/ppr.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
import { check, findAllTelemetryEvents } from 'next-test-utils'

createNextDescribe(
'ppr',
{
files: __dirname,
env: {
NEXT_TELEMETRY_DEBUG: '1',
},
},
({ next, isNextDev, isNextStart }) => {
it('should indicate the feature is experimental', async () => {
Expand All @@ -24,6 +27,19 @@ createNextDescribe(
expect(next.cliOutput).toContain('◐ /suspense/node/nested/[slug]')
})
})

describe('telemetry', () => {
it('should send ppr feature usage event', async () => {
const events = findAllTelemetryEvents(
next.cliOutput,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(events).toContainEqual({
featureName: 'experimental/ppr',
invocationCount: 1,
})
})
})
}
describe.each([
{ pathname: '/suspense/node' },
Expand Down