Skip to content

Problem with --experimental-loader with @opentelemetry/instrumentation/hook.mjs in Node.js 24+ #181

@monwolf

Description

@monwolf

Summary

When using @opentelemetry/instrumentation/hook.mjs with the --experimental-loader flag in Node.js 24+, the application hangs in what appears to be an infinite loop, consuming increasingly more memory over time until the process crashes.

OpenTelemetry Setup Code

import { Producer } from "@platformatic/kafka"
const logger = {
    info: console.log,
    error: console.error,
};

const start = async () => {
    logger.info("App started on port: " + 3000);
};

start();

export {Producer};

package.json

{
  "name": "test-otel",
  "version": "1.0.0",
  "description": "",
  "license": "ISC",
  "author": "",
  "type": "module",
  "main": "dist/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "tsc:b": "tsc --build"
  },
  "dependencies": {
    "@opentelemetry/api": "^1.9.0",
    "@opentelemetry/auto-instrumentations-node": "^0.67.2",
    "@opentelemetry/host-metrics": "^0.37.0",
    "@opentelemetry/sdk-node": "^0.208.0",
    "@platformatic/kafka": "1.17.1"
  },
  "devDependencies": {
    "typescript": "^5.9.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "outDir": "./dist",
    "rootDir": "./src",
    "target": "esnext",
    "strict": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*"],
  "exclude": ["test"]
}

run

    npm run tsc:b
    $env:NODE_OPTIONS = "--experimental-loader=@opentelemetry/instrumentation/hook.mjs"
    node --trace-warnings ./dist/index.js

If I remove the dependency, the application starts fine.

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