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 for React Compiler usage #68079

Merged
merged 1 commit into from
Jul 29, 2024
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
15 changes: 15 additions & 0 deletions packages/next/src/telemetry/events/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type EventCliSessionStarted = {
pagesDir: boolean | null
staticStaleTime: number | null
dynamicStaleTime: number | null
reactCompiler: boolean
reactCompilerCompilationMode: string | null
reactCompilerPanicThreshold: string | null
}

function hasBabelConfig(dir: string): boolean {
Expand Down Expand Up @@ -83,6 +86,9 @@ export function eventCliSession(
| 'reactStrictMode'
| 'staticStaleTime'
| 'dynamicStaleTime'
| 'reactCompiler'
| 'reactCompilerCompilationMode'
| 'reactCompilerPanicThreshold'
>
): { eventName: string; payload: EventCliSessionStarted }[] {
// This should be an invariant, if it fails our build tooling is broken.
Expand Down Expand Up @@ -126,6 +132,15 @@ export function eventCliSession(
pagesDir: event.pagesDir,
staticStaleTime: nextConfig.experimental.staleTimes?.static ?? null,
dynamicStaleTime: nextConfig.experimental.staleTimes?.dynamic ?? null,
reactCompiler: Boolean(nextConfig.experimental.reactCompiler),
reactCompilerCompilationMode:
typeof nextConfig.experimental.reactCompiler !== 'boolean'
? nextConfig.experimental.reactCompiler?.compilationMode ?? null
: null,
reactCompilerPanicThreshold:
typeof nextConfig.experimental.reactCompiler !== 'boolean'
? nextConfig.experimental.reactCompiler?.panicThreshold ?? null
: null,
}
return [{ eventName: EVENT_VERSION, payload }]
}
5 changes: 5 additions & 0 deletions test/integration/telemetry/next.config.reactCompiler-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
reactCompiler: true
}
}
8 changes: 8 additions & 0 deletions test/integration/telemetry/next.config.reactCompiler-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
experimental: {
reactCompiler: {
compilationMode: 'annotation',
panicThreshold: 'CRITICAL_ERRORS'
}
}
}
84 changes: 84 additions & 0 deletions test/integration/telemetry/test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,90 @@ describe('config telemetry', () => {
invocationCount: 1,
})
})

it('emits telemetry for default React Compiler options', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})

try {
const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event).toMatch(/"reactCompiler": false/)
expect(event).toMatch(/"reactCompilerCompilationMode": null/)
expect(event).toMatch(/"reactCompilerPanicThreshold": null/)
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
}
})

it('emits telemetry for enabled React Compiler', async () => {
await fs.rename(
path.join(appDir, 'next.config.reactCompiler-base'),
path.join(appDir, 'next.config.js')
)

let stderr
try {
const app = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
stderr = app.stderr
const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event).toMatch(/"reactCompiler": true/)
expect(event).toMatch(/"reactCompilerCompilationMode": null/)
expect(event).toMatch(/"reactCompilerPanicThreshold": null/)
} 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.reactCompiler-base')
)
}
})

it('emits telemetry for configured React Compiler options', async () => {
await fs.rename(
path.join(appDir, 'next.config.reactCompiler-options'),
path.join(appDir, 'next.config.js')
)

let stderr
try {
const app = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
stderr = app.stderr
const event = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event).toMatch(/"reactCompiler": true/)
expect(event).toMatch(/"reactCompilerCompilationMode": "annotation"/)
expect(event).toMatch(
/"reactCompilerPanicThreshold": "CRITICAL_ERRORS"/
)
} 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.reactCompiler-options')
)
}
})
}
)
})
Loading