open-telemetry / opentelemetry-js-contrib

OpenTelemetry instrumentation for JavaScript modules
https://opentelemetry.io
Apache License 2.0
670 stars 494 forks source link

Node v14.17.6 causing the node:crypto module not found issue #2357

Closed architgarg95 closed 1 month ago

architgarg95 commented 1 month ago

What version of OpenTelemetry are you using?

0.52.0

What version of Node are you using?

v14.17.6

What did you do?

implemented simple telemetry

What did you expect to see?

telemetry starting correctly and exporting data correctly

What did you see instead?

application fails to run becuase of node:crypto module not found

Additional context

This issue occurs only with the node v14.17.6 or prior version, somehow getting the error node:crypto module not found which in the call stack shows is required by gcp-detector, this gcp-detector internally uses the gaxios which is further dependent on 'node:crypto' module

Error stack below:

Error: Cannot find module 'node:crypto' [0] Require stack: [0] - .../src/main/node/node_modules/gaxios/node_modules/uuid/dist/rng.js [0] - .../src/main/node/node_modules/gaxios/node_modules/uuid/dist/v1.js [0] - .../src/main/node/node_modules/gaxios/node_modules/uuid/dist/index.js [0] - .../src/main/node/node_modules/gaxios/build/src/gaxios.js [0] - .../src/main/node/node_modules/gaxios/build/src/index.js [0] - .../src/main/node/node_modules/gcp-metadata/build/src/index.js [0] - .../src/main/node/node_modules/@opentelemetry/resource-detector-gcp/build/src/detectors/GcpDetector.js [0] - .../src/main/node/node_modules/@opentelemetry/resource-detector-gcp/build/src/detectors/index.js [0] - .../src/main/node/node_modules/@opentelemetry/resource-detector-gcp/build/src/index.js [0] - .../src/main/node/node_modules/@opentelemetry/auto-instrumentations-node/build/src/utils.js [0] - .../src/main/node/node_modules/@opentelemetry/auto-instrumentations-node/build/src/index.js

architgarg95 commented 1 month ago

Does anyone know about this??

dyladan commented 1 month ago

The quickest workaround here assuming you aren't on GCP is to install the instrumentations and detectors you need manually without using the auto-instrumentations-node package. That package adds a lot of things and dependencies and it looks like we may not have control over this.

dyladan commented 1 month ago

One other thing you can try is to update to at least 14.18.x which adds support for require('node:*') style imports.

trentm commented 1 month ago

I'll try to track down the dep update that resulted in this. I'm guessing it is a transitive dep, so pinning is hard.

trentm commented 1 month ago

I wonder if this could have been from https://github.com/googleapis/gaxios/pull/638 There was a short while when gaxios@6 (the current version used by @opentelemetry/resource-detector-gcp had a dependency on uuid@10, which broke support for earlier Node.js v14. Then gaxios reverted back to uuid@9.

@architgarg95 Could you please show the output of npm ls gaxios and npm ls uuid on your tree that is hitting this issue?

trentm commented 1 month ago

Actually, it looks like there has not been a new gaxios@6 release since it moved back to using uuid@9. gaxios@6.7.0 is the problematic verison. So a workaround, until there is a new gaxios release, would be to pin to release gaxios@6.6.0, if possible.

trentm commented 1 month ago

I knew this was familiar, I reported this earlier: https://github.com/googleapis/gaxios/issues/637 The result of that was the https://github.com/googleapis/gaxios/pull/638 fix. We are now just waiting for a new release of gaxios.

architgarg95 commented 1 month ago

I wonder if this could have been from https://github.com/googleapis/gaxios/pull/638 There was a short while when gaxios@6 (the current version used by @opentelemetry/resource-detector-gcp had a dependency on uuid@10, which broke support for earlier Node.js v14. Then gaxios reverted back to uuid@9.

@architgarg95 Could you please show the output of npm ls gaxios and npm ls uuid on your tree that is hitting this issue?

Its from gaxios, it has code for require('node:crypto') which is causing this issue

trentm commented 1 month ago

@architgarg95 Yes, I know it is from gaxios. Could you please show the output of npm ls gaxios and npm ls uuid in your tree. That will show me the exact versions, which helps clarify that I understand the issue.

architgarg95 commented 1 month ago

npm ls gaxios output: └─┬ @opentelemetry/auto-instrumentations-node@0.47.1 └─┬ @opentelemetry/resource-detector-gcp@0.29.10 └─┬ gcp-metadata@6.1.0 └── gaxios@6.7.0

npm ls uuid output: @opentelemetry/auto-instrumentations-node@0.47.1 │ └─┬ @opentelemetry/resource-detector-gcp@0.29.10 │ └─┬ gcp-metadata@6.1.0 │ └─┬ gaxios@6.7.0 │ └── uuid@10.0.0

architgarg95 commented 1 month ago

@trentm Do you know anything about this??

trentm commented 1 month ago

@architgarg95 Thanks for the 'npm ls ...' output. So, yes, you have hit the issue with gaxios@6.7.0 being a minor release that broke support for Node.js versions less than 14.18. I've asked (on the gaxios issue linked above) if a new release woiuld be possible. That would fix you.

Other options:

trentm commented 1 month ago

There is now a gaxios@6.7.1 release with a fix.

If I now install the auto-instrumentations-node package, the resulting install has gaxios@6.7.1 and uuid@9, which should now work with Node.js 14:

% npm install @opentelemetry/auto-instrumentations-node
⸨  ░░░░░░░░░░░░░░░░⸩ ⠦ fetchMetadata: sill resolveWithNewModule @types/mysql@2.15.22 checking installable status

> protobufjs@7.3.2 postinstall /Users/trentm/tmp/asdf.20240809T154923/node_modules/protobufjs
> node scripts/postinstall

npm WARN asdf.20240809t154923@1.0.0 No description
npm WARN asdf.20240809t154923@1.0.0 No repository field.

+ @opentelemetry/auto-instrumentations-node@0.49.1
added 151 packages from 152 contributors and audited 151 packages in 12.656s

9 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

% npm ls uuid
asdf.20240809t154923@1.0.0 /Users/trentm/tmp/asdf.20240809T154923
└─┬ @opentelemetry/auto-instrumentations-node@0.49.1
  └─┬ @opentelemetry/resource-detector-gcp@0.29.10
    └─┬ gcp-metadata@6.1.0
      └─┬ gaxios@6.7.1
        └── uuid@9.0.1