Skip to content

Commit

Permalink
Add telemetry for stable features (#44201)
Browse files Browse the repository at this point in the history
Follow up to #44195 #44194.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [x] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
shuding committed Dec 20, 2022
1 parent 966d2b1 commit e847b49
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -2147,6 +2147,16 @@ export default async function getBaseWebpackConfig(
['swcImportSource', !!jsConfig?.compilerOptions?.jsxImportSource],
['swcEmotion', !!config.compiler?.emotion],
['turbotrace', !!config.experimental.turbotrace],
['transpilePackages', !!config.transpilePackages],
[
'allowMiddlewareResponseBody',
!!config.allowMiddlewareResponseBody,
],
[
'skipMiddlewareUrlNormalize',
!!config.skipMiddlewareUrlNormalize,
],
['skipTrailingSlashRedirect', !!config.skipTrailingSlashRedirect],
SWCBinaryTarget,
].filter<[Feature, boolean]>(Boolean as any)
)
Expand Down
8 changes: 8 additions & 0 deletions packages/next/build/webpack/plugins/telemetry-plugin.ts
Expand Up @@ -37,6 +37,10 @@ export type Feature =
| 'swcEmotion'
| `swc/target/${SWC_TARGET_TRIPLE}`
| 'turbotrace'
| 'transpilePackages'
| 'allowMiddlewareResponseBody'
| 'skipMiddlewareUrlNormalize'
| 'skipTrailingSlashRedirect'

interface FeatureUsage {
featureName: Feature
Expand Down Expand Up @@ -96,6 +100,10 @@ const BUILD_FEATURES: Array<Feature> = [
'swc/target/aarch64-unknown-linux-musl',
'swc/target/aarch64-pc-windows-msvc',
'turbotrace',
'transpilePackages',
'allowMiddlewareResponseBody',
'skipMiddlewareUrlNormalize',
'skipTrailingSlashRedirect',
]

const ELIMINATED_PACKAGES = new Set<string>()
Expand Down
4 changes: 4 additions & 0 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -166,6 +166,10 @@ export type EventBuildFeatureUsage = {
| 'turbotrace'
| 'build-lint'
| 'vercelImageGeneration'
| 'transpilePackages'
| 'allowMiddlewareResponseBody'
| 'skipMiddlewareUrlNormalize'
| 'skipTrailingSlashRedirect'
invocationCount: number
}
export function eventBuildFeatureUsage(
Expand Down
5 changes: 5 additions & 0 deletions test/integration/telemetry/next.config.middleware-options
@@ -0,0 +1,5 @@
module.exports = {
allowMiddlewareResponseBody: true,
skipMiddlewareUrlNormalize: true,
skipTrailingSlashRedirect: true,
}
3 changes: 3 additions & 0 deletions test/integration/telemetry/next.config.transpile-packages
@@ -0,0 +1,3 @@
module.exports = {
transpilePackages: ["foo"]
}
60 changes: 60 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -1090,4 +1090,64 @@ describe('Telemetry CLI', () => {
invocationCount: 1,
})
})

it('emits telemetry for transpilePackages', async () => {
await fs.rename(
path.join(appDir, 'next.config.transpile-packages'),
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.transpile-packages')
)

const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'transpilePackages',
invocationCount: 1,
})
})

it('emits telemetry for middleware related options', async () => {
await fs.rename(
path.join(appDir, 'next.config.middleware-options'),
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.middleware-options')
)

const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'allowMiddlewareResponseBody',
invocationCount: 1,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'skipMiddlewareUrlNormalize',
invocationCount: 1,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'skipTrailingSlashRedirect',
invocationCount: 1,
})
})
})

0 comments on commit e847b49

Please sign in to comment.