Skip to content

Instrumentation hook not resolved with mixed src dir and root instrumentation file #50420

Open
@lkostrowski

Description

@lkostrowski

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.7.0
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 8.2.0
    Relevant packages:
      next: 13.4.5-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.7.4

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/lkostrowski/next-instrumentation-src-repro

To Reproduce

Reproduction is example with-opentelemetry.

Files were moved to src
instrumentation.ts prints console.log

Describe the Bug

Docs say to create instrumentation.ts in the root of the project.

If app has no src dir, file in root indeed works. If src exists, file src/instrumentation.ts also works.

With app in src and /instrumentation.ts combination, file is not resolved

Expected Behavior

I see one of following behaviors

Option 1

If this is expected behavior, I'd expect docs to say that explicitly and Next server/devserver/build should inform me, that I have created a file in the wrong location and I should move it

Option 2

  1. Allow both directions.
  2. Add test case where app in src work together with instrumentation in root
  3. Check against duplicated files and break build/server if duplicated, to avoid unexpected behavior

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    InstrumentationRelated to Next.js Instrumentation.bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions