Skip to content

Instrumentation.ts issues #287

@shawnmclean

Description

@shawnmclean

I'm trying to use this package when following this open telemetry example: https://nextjs.org/docs/app/building-your-application/optimizing/open-telemetry

When I swap out process.env.NEXT_RUNTIME for env.NEXT_RUNTIME with all the configs and console logs, it seems to try importing the node package and throws a module resolution issue.

import { env } from "./env";

export async function register() {
  console.log("env", env.NEXT_RUNTIME);
  console.log("process.env", process.env.NEXT_RUNTIME);
  if (env.NEXT_RUNTIME === "nodejs") {
    console.log("instrumentation registering");
    await import("./instrumentation.node");
  }
}

This is a weird issue because all the console logs work well during next dev. They write out nodejs. But when I load a route, I don't see the logs but an error is thrown.

This error is not thrown if I change the check to process.env.NEXT_RUNTIME === 'nodejs'.

I have it wired up to next.config too with the jiti.

Is next doing some funny stuff here why its not working with your library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions