Unverified Commit 13f68deb authored by Keen Yee Liau's avatar Keen Yee Liau Committed by GitHub

Collect feature usage for optimizeCss (#29828)

`optimizeCss` is a feature that inlines critical CSS using critters.
The Aurora team would like to gauge adoption rate for this feature.



## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [x] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes
parent ad565c40
...@@ -66,6 +66,8 @@ import { ...@@ -66,6 +66,8 @@ import {
eventBuildFeatureUsage, eventBuildFeatureUsage,
eventNextPlugins, eventNextPlugins,
eventTypeCheckCompleted, eventTypeCheckCompleted,
EVENT_BUILD_FEATURE_USAGE,
EventBuildFeatureUsage,
} from '../telemetry/events' } from '../telemetry/events'
import { Telemetry } from '../telemetry/storage' import { Telemetry } from '../telemetry/storage'
import { CompilerResult, runCompiler } from './compiler' import { CompilerResult, runCompiler } from './compiler'
...@@ -1137,6 +1139,15 @@ export default async function build( ...@@ -1137,6 +1139,15 @@ export default async function build(
) )
} }
const optimizeCss: EventBuildFeatureUsage = {
featureName: 'experimental/optimizeCss',
invocationCount: config.experimental.optimizeCss ? 1 : 0,
}
telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: optimizeCss,
})
await promises.writeFile( await promises.writeFile(
path.join(distDir, SERVER_FILES_MANIFEST), path.join(distDir, SERVER_FILES_MANIFEST),
JSON.stringify(requiredServerFiles), JSON.stringify(requiredServerFiles),
......
...@@ -120,9 +120,13 @@ export function eventBuildOptimize( ...@@ -120,9 +120,13 @@ export function eventBuildOptimize(
} }
} }
const EVENT_BUILD_FEATURE_USAGE = 'NEXT_BUILD_FEATURE_USAGE' export const EVENT_BUILD_FEATURE_USAGE = 'NEXT_BUILD_FEATURE_USAGE'
type EventBuildFeatureUsage = { export type EventBuildFeatureUsage = {
featureName: string featureName:
| 'next/image'
| 'next/script'
| 'next/dynamic'
| 'experimental/optimizeCss'
invocationCount: number invocationCount: number
} }
export function eventBuildFeatureUsage( export function eventBuildFeatureUsage(
......
module.exports = {
experimental: {
optimizeCss: true
}
}
\ No newline at end of file
...@@ -567,6 +567,7 @@ describe('Telemetry CLI', () => { ...@@ -567,6 +567,7 @@ describe('Telemetry CLI', () => {
env: { NEXT_TELEMETRY_DEBUG: 1 }, env: { NEXT_TELEMETRY_DEBUG: 1 },
}) })
const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
regex.exec(stderr).pop() // optimizeCss
const image = regex.exec(stderr).pop() const image = regex.exec(stderr).pop()
expect(image).toContain(`"featureName": "next/image"`) expect(image).toContain(`"featureName": "next/image"`)
expect(image).toContain(`"invocationCount": 1`) expect(image).toContain(`"invocationCount": 1`)
...@@ -577,4 +578,26 @@ describe('Telemetry CLI', () => { ...@@ -577,4 +578,26 @@ describe('Telemetry CLI', () => {
expect(dynamic).toContain(`"featureName": "next/dynamic"`) expect(dynamic).toContain(`"featureName": "next/dynamic"`)
expect(dynamic).toContain(`"invocationCount": 1`) expect(dynamic).toContain(`"invocationCount": 1`)
}) })
it('emits telemetry for usage of `optimizeCss`', async () => {
await fs.rename(
path.join(appDir, 'next.config.optimize-css'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.optimize-css')
)
const regex = /NEXT_BUILD_FEATURE_USAGE[\s\S]+?{([\s\S]+?)}/g
const optimizeCss = regex.exec(stderr).pop()
expect(optimizeCss).toContain(`"featureName": "experimental/optimizeCss"`)
expect(optimizeCss).toContain(`"invocationCount": 1`)
})
}) })
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