Skip to content

Add instrumentationInject for adapter-supplied instrumentation - #100658

Merged
mischnic merged 31 commits into
vercel:canaryfrom
kakadiadarpan:darpan/tracing-default
Nov 3, 2026
Merged

mischnic merged 31 commits into
vercel:canaryfrom
kakadiadarpan:darpan/tracing-default

Conversation

@kakadiadarpan

@kakadiadarpan kakadiadarpan commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What?

Adds an instrumentationInject?: string[] config option. Next.js compiles one module that runs every entry's register and onRequestError, then the project's own instrumentation.{ts,js} if it has one. This works like instrumentationClientInject does for the client.

// set by a deployment adapter in modifyConfig, or a config wrapper like withSentry
config.instrumentationInject ??= []
config.instrumentationInject.push('./path/to/instrumentation.js')
instrumentation slot
  → each instrumentationInject entry, in array order
  → then the project's instrumentation file, if there is one

Why?

Hosting platforms want to give every app default instrumentation, such as OpenTelemetry tracing. Today that means asking users to add an instrumentation.ts and a dependency to their project. This hook lets an adapter or a config wrapper supply the module at build time instead. The user's files, package.json and lockfile stay untouched, and Next.js installs nothing.

How?

  • Anyone can set the field: a deployment adapter in modifyConfig, or a config wrapper such as withSentry. Whoever sets it decides whether to inject when the project already has its own instrumentation file.
  • Both bundlers generate the same CommonJS module: it requires every entry from the project root, then the project's instrumentation file, and passes them to combineInstrumentation (next/dist/lib/combine-instrumentation).
  • webpack compiles a stub entry through next-instrumentation-inject-loader. Turbopack uses a virtual instrumentation.inject.cjs at the project root, so a type: module package.json can't change how it parses.
  • register hooks run in array order. onRequestError hooks run concurrently, so a slow or hanging handler can't stop the project's own from running. A hook that throws, or a module with top-level await that fails to load, doesn't stop the others. The error is rethrown after all have run, as an AggregateError when more than one fails, so Next.js surfaces it as it does for a single file. A module without top-level await that throws while loading stops startup, as a single broken file does today.
  • Modules that use top-level await come back from require() as promises. combineInstrumentation awaits each one, and marks them handled up front so a later rejection isn't reported as unhandled while an earlier hook runs.
  • Entries can be package names, project-relative paths, or absolute paths. The bundler resolves them from the project root, as it would an import. Package entries keep their name, so serverExternalPackages and the built-in externals list apply, and an external entry is still included in the server trace. Absolute paths are rewritten to project-relative ones for Turbopack, which resolves a leading / from the project root.
  • instrumentationInject defaults to [], like instrumentationClientInject, so modifyConfig can push to it.
  • To find the project file, webpack tries each pageExtensions extension, in config order, at the project root and then in src/. Turbopack uses its usual instrumentation lookup, which also checks parent folders up to outputFileTracingRoot and tries longer extensions first. With more than one candidate file, the two can pick different ones.
  • An entry that doesn't resolve fails the build, so whoever sets the field should check it first.

Tests

test/e2e/app-dir/inject-instrumentation covers five cases with webpack and Turbopack:

  1. With two injected entries and no project file, both register() calls run, in order.
  2. With a project instrumentation file, both injected register() calls run, then the project's.
  3. With pageExtensions: ['page.ts', …], the project's instrumentation.page.ts is chained.
  4. With no inject and no file, there's no instrumentation.
  5. Package entries: one listed in serverExternalPackages stays out of the Node server bundles and appears in instrumentation.js.nft.json, and a bundled one is compiled in. The bundle check reads build output, so it's gated to !deploy, and the trace check to start.

The fixtures cover a relative and an absolute entry, an injected entry and a project file that both use top-level await, and an injected module that imports a sibling file. lib/combine-instrumentation.test.ts covers register order, error isolation, onRequestError arguments, concurrent onRequestError handlers (a hanging one doesn't block the rest), promise modules, and that a later rejection isn't left unhandled.

Related

nextjs/adapter-vercel#148

@github-actions github-actions Bot added tests Turbopack Related to Turbopack with Next.js. type: next labels Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Failing test suites

Commit: 3eca83f | About building and testing Next.js

pnpm test-deploy test/e2e/app-dir/inject-instrumentation/inject-instrumentation.test.ts (job)

  • inject-instrumentation > a project instrumentation file chains after the inject > runs the injected registers, then the project register (DD)
  • inject-instrumentation > a project instrumentation file with a compound page extension > chains instrumentation.page.ts after the inject (DD)
  • inject-instrumentation > injected package resolution > runs injected packages and filesystem entries (DD)
  • inject-instrumentation > instrumentationInject without a project file > runs every injected register in Node.js, in order (DD)
  • inject-instrumentation > instrumentationInject without a project file > runs every injected register in the Edge runtime, in order (DD)
  • inject-instrumentation > no inject and no project file > runs no instrumentation (DD)
Expand output

● inject-instrumentation › injected package resolution › runs injected packages and filesystem entries

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › injected package resolution › keeps the opted-out implementation out of emitted server bundles

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › injected package resolution › traces the external instrumentation package

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › instrumentationInject without a project file › runs every injected register in Node.js, in order

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › instrumentationInject without a project file › runs every injected register in the Edge runtime, in order

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › a project instrumentation file chains after the inject › runs the injected registers, then the project register

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › a project instrumentation file with a compound page extension › chains instrumentation.page.ts after the inject

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › no inject and no project file › runs no instrumentation

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

pnpm test-deploy-experimental-turbo test/e2e/app-dir/inject-instrumentation/inject-instrumentation.test.ts (turbopack) (Experimental) (job)

  • inject-instrumentation > a project instrumentation file chains after the inject > runs the injected registers, then the project register (DD)
  • inject-instrumentation > a project instrumentation file with a compound page extension > chains instrumentation.page.ts after the inject (DD)
  • inject-instrumentation > injected package resolution > runs injected packages and filesystem entries (DD)
  • inject-instrumentation > instrumentationInject without a project file > runs every injected register in Node.js, in order (DD)
  • inject-instrumentation > instrumentationInject without a project file > runs every injected register in the Edge runtime, in order (DD)
  • inject-instrumentation > no inject and no project file > runs no instrumentation (DD)
Expand output

● inject-instrumentation › injected package resolution › runs injected packages and filesystem entries

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › injected package resolution › keeps the opted-out implementation out of emitted server bundles

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › injected package resolution › traces the external instrumentation package

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › instrumentationInject without a project file › runs every injected register in Node.js, in order

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › instrumentationInject without a project file › runs every injected register in the Edge runtime, in order

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › a project instrumentation file chains after the inject › runs the injected registers, then the project register

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › a project instrumentation file with a compound page extension › chains instrumentation.page.ts after the inject

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › no inject and no project file › runs no instrumentation

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

pnpm test-deploy test/e2e/app-dir/inject-instrumentation/inject-instrumentation.test.ts (job)

  • inject-instrumentation > a project instrumentation file chains after the inject > runs the injected registers, then the project register (DD)
  • inject-instrumentation > a project instrumentation file with a compound page extension > chains instrumentation.page.ts after the inject (DD)
  • inject-instrumentation > injected package resolution > runs injected packages and filesystem entries (DD)
  • inject-instrumentation > instrumentationInject without a project file > runs every injected register in Node.js, in order (DD)
  • inject-instrumentation > instrumentationInject without a project file > runs every injected register in the Edge runtime, in order (DD)
  • inject-instrumentation > no inject and no project file > runs no instrumentation (DD)
Expand output

● inject-instrumentation › injected package resolution › runs injected packages and filesystem entries

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › injected package resolution › keeps the opted-out implementation out of emitted server bundles

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › injected package resolution › traces the external instrumentation package

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › instrumentationInject without a project file › runs every injected register in Node.js, in order

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › instrumentationInject without a project file › runs every injected register in the Edge runtime, in order

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › a project instrumentation file chains after the inject › runs the injected registers, then the project register

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › a project instrumentation file with a compound page extension › chains instrumentation.page.ts after the inject

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

● inject-instrumentation › no inject and no project file › runs no instrumentation

Failed to link project  Vercel CLI 65.10.0
Error: No existing credentials found. Please run `vercel login` or pass "--token"
Learn More: https://err.sh/vercel/no-credentials-found (1)

  656 |
  657 |     if (linkRes.exitCode !== 0) {
> 658 |       throw new Error(
      |             ^
  659 |         `Failed to link project ${linkRes.stdout} ${linkRes.stderr} (${linkRes.exitCode})`
  660 |       )
  661 |     }

  at NextDeployInstance.deploy (lib/next-modes/next-deploy.ts:658:13)
  at NextDeployInstance.start (lib/next-modes/next-deploy.ts:1247:5)
  at lib/e2e-utils/index.ts:342:13
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at lib/e2e-utils/index.ts:339:9
  at Span.traceAsyncFn (../packages/next/src/trace/trace.ts:156:14)
  at createNext (lib/e2e-utils/index.ts:294:12)
  at Object.<anonymous> (lib/e2e-utils/index.ts:406:18)

@kakadiadarpan kakadiadarpan changed the title Let the adapter inject instrumentation instead of bundling @vercel/otel Next.js injectInstrumentation: default tracing without an instrumentation.ts Oct 27, 2026
@kakadiadarpan
kakadiadarpan force-pushed the darpan/tracing-default branch from b3db38b to f0581c7 Compare October 27, 2026 14:05
@kakadiadarpan kakadiadarpan changed the title Next.js injectInstrumentation: default tracing without an instrumentation.ts Add injectInstrumentation config Oct 27, 2026
@kakadiadarpan kakadiadarpan changed the title Add injectInstrumentation config Add injectInstrumentation for adapter-supplied instrumentation Oct 27, 2026
@kakadiadarpan
kakadiadarpan force-pushed the darpan/tracing-default branch from 1c1fb13 to 9762bd2 Compare October 27, 2026 17:05
@kakadiadarpan
kakadiadarpan marked this pull request as ready for review October 28, 2026 08:13
@kakadiadarpan
kakadiadarpan force-pushed the darpan/tracing-default branch from 9762bd2 to bdb7103 Compare October 28, 2026 10:58
Comment thread crates/next-api/src/project.rs Resolved
Comment thread crates/next-api/src/project.rs Resolved
Comment thread crates/next-api/src/project.rs Resolved
@kakadiadarpan
kakadiadarpan force-pushed the darpan/tracing-default branch from bdb7103 to 1e57c97 Compare October 28, 2026 11:59
@mischnic

mischnic commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

A project instrumentation file always wins, including one in a parent folder up to outputFileTracingRoot.

What does that mean? It shoudl execute all of them. No file "wins"?

The adapter sets the field in modifyConfig. Apps don't set it.

Anyone can set them. withSentry for example could also set it

@kakadiadarpan kakadiadarpan changed the title Add injectInstrumentation for adapter-supplied instrumentation Add injectInstrumentation to chain modules into the instrumentation slot Oct 29, 2026
@kakadiadarpan
kakadiadarpan force-pushed the darpan/tracing-default branch from 858ddec to f6c0652 Compare October 29, 2026 13:28
@kakadiadarpan

Copy link
Copy Markdown
Contributor Author

@mischnic

A project instrumentation file always wins

Right, nothing wins anymore. Since d09b2e7 every entry runs in array order, then the project's own instrumentation.*. I fixed that line in the description.

The adapter sets the field in modifyConfig. Apps don't set it.

Agreed. The description now says anyone can set it, an adapter in modifyConfig or a wrapper like withSentry. Whoever sets it decides whether to inject when the project has its own file.

kakadiadarpan and others added 18 commits October 30, 2026 22:56
Every module is required before any hook runs, so a later async module
could reject while an earlier hook was awaiting, and Node would report
an unhandled rejection. Attach a no-op handler when combining; callEach
still awaits each promise and collects its error.
NextConfigComplete types the field as string[], so modifyConfig can push to
it without a guard, matching instrumentationClientInject.
The startup check resolves entries with Node's rules, which don't try .ts or
.tsx, so an import-style path that both bundlers accept was reported as not
resolving.
Both lists reach webpack only through loader options and the client entry,
which the persistent cache doesn't key on. With a warm .next/cache, adding or
removing an entry reused the previously generated instrumentation module.
The config merge copied the array references, so a push in modifyConfig
changed Next's shared default (or a cached user config), and a later load in
the same process saw the entry twice.
A hook that throws, or a module with top-level await that fails to load, is
collected. A module without top-level await that throws while loading stops
startup before combineInstrumentation runs, as a single broken file does
today.
@mischnic
mischnic force-pushed the darpan/tracing-default branch from 35dabcf to 6dc245e Compare October 30, 2026 22:29
@mischnic mischnic changed the title Add injectInstrumentation for adapter-supplied instrumentation Add instrumentationInject for adapter-supplied instrumentation Oct 30, 2026
kakadiadarpan added a commit to kakadiadarpan/adapter-vercel that referenced this pull request Nov 2, 2026
vercel/next.js#100658 renamed the config option to match
instrumentationClientInject.

@lucleray lucleray left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks! a few nits inline 👍

kakadiadarpan and others added 3 commits November 2, 2026 12:55
They ran one after another, so an injected handler that hung kept the
project's own onRequestError from ever running, and the request path awaits
it. Run them together and collect failures the same way. register keeps its
array order.
@mischnic
mischnic merged commit 2ebb7ea into vercel:canary Nov 3, 2026
347 of 355 checks passed
jamiboym added a commit that referenced this pull request Nov 3, 2026
Resolve conflicts with #100658 (instrumentationInject). Keep both sides: this branch's route-types bootstrap and Turbopack route publisher, and canary's webpack-only instrumentation hook setup. Combine the Rust filesystem imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Turbopack Related to Turbopack with Next.js. type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants