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

Stablize instrumentation.js #68853

Merged
merged 2 commits into from
Aug 21, 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
9 changes: 1 addition & 8 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,15 +861,9 @@ export default async function build(
)

const rootDir = path.join((pagesDir || appDir)!, '..')
const instrumentationHookEnabled = Boolean(
config.experimental.instrumentationHook
)

const includes = [
middlewareDetectionRegExp,
...(instrumentationHookEnabled
? [instrumentationHookDetectionRegExp]
: []),
instrumentationHookDetectionRegExp,
]

const rootPaths = Array.from(await getFilesInDir(rootDir))
Expand Down Expand Up @@ -1350,7 +1344,6 @@ export default async function build(
currentEntrypoints,
currentEntryIssues,
manifestLoader,
nextConfig: config,
devRewrites: undefined,
productionRewrites: customRoutes.rewrites,
logErrors: false,
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
.optional(),
optimizePackageImports: z.array(z.string()).optional(),
optimizeServerReact: z.boolean().optional(),
instrumentationHook: z.boolean().optional(),
clientTraceMetadata: z.array(z.string()).optional(),
turbotrace: z
.object({
Expand Down
6 changes: 0 additions & 6 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,6 @@ export interface ExperimentalConfig {
*/
webpackMemoryOptimizations?: boolean

/**
*
*/
instrumentationHook?: boolean

/**
* The array of the meta tags to the client injected by tracing propagation data.
*/
Expand Down Expand Up @@ -1031,7 +1026,6 @@ export const defaultConfig: NextConfig = {
turbotrace: undefined,
typedRoutes: false,
typedEnv: false,
instrumentationHook: false,
clientTraceMetadata: undefined,
parallelServerCompiles: false,
parallelServerBuildTraces: false,
Expand Down
7 changes: 7 additions & 0 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ function assignDefaults(
silent
)

warnOptionHasBeenDeprecated(
huozhi marked this conversation as resolved.
Show resolved Hide resolved
result,
'experimental.instrumentationHook',
'`experimental.instrumentationHook` is no longer needed to be configured in Next.js',
silent
)

warnOptionHasBeenMovedOutOfExperimental(
result,
'bundlePagesExternals',
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ export async function createHotReloaderTurbopack(

currentEntryIssues,
manifestLoader,
nextConfig: opts.nextConfig,
devRewrites: opts.fsChecker.rewrites,
productionRewrites: undefined,
logErrors: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/next/src/server/dev/turbopack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ export async function handleEntrypoints({

currentEntryIssues,
manifestLoader,
nextConfig,
devRewrites,
productionRewrites,
logErrors,
Expand All @@ -721,7 +720,6 @@ export async function handleEntrypoints({

currentEntryIssues: EntryIssuesMap
manifestLoader: TurbopackManifestLoader
nextConfig: NextConfigComplete
devRewrites: SetupOpts['fsChecker']['rewrites'] | undefined
productionRewrites: CustomRoutes['rewrites'] | undefined
logErrors: boolean
Expand Down Expand Up @@ -793,7 +791,7 @@ export async function handleEntrypoints({

currentEntrypoints.global.middleware = middleware

if (nextConfig.experimental.instrumentationHook && instrumentation) {
if (instrumentation) {
const processInstrumentation = async (
name: string,
prop: 'nodeJs' | 'edge'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,7 @@ async function startWatcher(opts: SetupOpts) {
]
continue
}
if (
isInstrumentationHookFile(rootFile) &&
nextConfig.experimental.instrumentationHook
) {
if (isInstrumentationHookFile(rootFile)) {
serverFields.actualInstrumentationHookFile = rootFile
await propagateServerField(
opts,
Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@ export default class NextNodeServer extends BaseServer<
}

protected async loadInstrumentationModule() {
if (
!this.serverOptions.dev &&
!!this.nextConfig.experimental.instrumentationHook
) {
if (!this.serverOptions.dev) {
try {
this.instrumentation = await dynamicRequire(
resolve(
Expand Down
1 change: 0 additions & 1 deletion test/e2e/app-dir/next-after-app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ module.exports = {
experimental: {
after: true,
testProxy: true,
instrumentationHook: true,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ describe('instrumentation-hook-rsc', () => {
describe('instrumentation', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
nextConfig: {
experimental: {
instrumentationHook: true,
},
},
skipDeployment: true,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ module.exports = {
flyingShuttle: {
mode: 'full',
},
instrumentationHook: true,
},
}
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/general/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
36 changes: 9 additions & 27 deletions test/e2e/instrumentation-hook/instrumentation-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,15 @@ const describeCase = (
})
}
describe('Instrumentation Hook', () => {
// TODO: investigate the failure with esm import
// createNextDescribe(
// 'with-esm-import',
// {
// files: path.join(__dirname, 'with-esm-import'),
// nextConfig: {
// experimental: {
// instrumentationHook: true,
// },
// },
// dependencies: {
// // This test is mostly for compatibility with this package
// '@vercel/otel': 'latest',
// },
// skipDeployment: true,
// },
// ({ next }) => {
// eslint-disable-next-line jest/no-commented-out-tests
// it('with-esm-import should run the instrumentation hook', async () => {
// await next.render('/')
// await check(
// () => next.cliOutput,
// /register in instrumentation\.js is running/
// )
// })
// }
// )
describeCase('with-esm-import', ({ next }) => {
it('with-esm-import should run the instrumentation hook', async () => {
await next.render('/')
await check(
() => next.cliOutput,
/register in instrumentation\.js is running/
)
})
})

describeCase('with-middleware', ({ next }) => {
it('with-middleware should run the instrumentation hook', async () => {
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/register-once/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/with-edge-api/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/with-edge-page/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
1 change: 1 addition & 0 deletions test/e2e/instrumentation-hook/with-esm-import/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as otel from '@vercel/otel'
import * as mod from 'my-lib'

export function register() {
console.log('register in instrumentation.js is running')
// make sure that this is not tree-shaken
if (process.env.DOESNT_EXIST_1234) otel()
if (process.env.DOESNT_EXIST_1234) mod.c()
}
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/with-esm-import/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/with-middleware/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/with-node-api/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/instrumentation-hook/with-node-page/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/on-request-error/basic/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/on-request-error/dynamic-routes/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/on-request-error/isr/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
6 changes: 1 addition & 5 deletions test/e2e/on-request-error/server-action-error/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
experimental: {
instrumentationHook: true,
clientTraceMetadata: [
'my-parent-span-id',
'my-test-key-1',
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/opentelemetry/instrumentation/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
4 changes: 2 additions & 2 deletions test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('opentelemetry', () => {
},
},
]) {
// turbopack does not support experimental.instrumentationHook
// turbopack does not support instrumentation.js
;(process.env.TURBOPACK || process.env.__NEXT_EXPERIMENTAL_PPR
? describe.skip
: describe)(env.name, () => {
Expand Down Expand Up @@ -836,7 +836,7 @@ describe('opentelemetry with disabled fetch tracing', () => {
await collector.shutdown()
})

// turbopack does not support experimental.instrumentationHook
// turbopack does not support instrumentation.js
;(process.env.TURBOPACK || process.env.__NEXT_EXPERIMENTAL_PPR
? describe.skip
: describe)('root context', () => {
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/rsc-layers-transform/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Config Experimental Warning', () => {
experimental: {
workerThreads: true,
scrollRestoration: true,
instrumentationHook: true,
parallelServerCompiles: true,
huozhi marked this conversation as resolved.
Show resolved Hide resolved
cpus: 2,
}
}
Expand All @@ -162,7 +162,7 @@ describe('Config Experimental Warning', () => {
experimental: {
workerThreads: true,
scrollRestoration: true,
instrumentationHook: true,
parallelServerCompiles: true,
cpus: 2,
}
}
Expand All @@ -172,7 +172,7 @@ describe('Config Experimental Warning', () => {
expect(stdout).toMatch(' · cpus')
expect(stdout).toMatch(' · workerThreads')
expect(stdout).toMatch(' · scrollRestoration')
expect(stdout).toMatch(' · instrumentationHook')
expect(stdout).toMatch(' · parallelServerCompiles')
})

it('should show unrecognized experimental features in warning but not in start log experiments section', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
instrumentationHook: true,
},
}
module.exports = {}
Loading