instana / nodejs

Node.js in-process collectors for Instana
MIT License
69 stars 36 forks source link

[Bug]: LRUCache is not a constructor error when using Instana layer with a custom layer #1032

Closed deepakthankachan closed 7 months ago

deepakthankachan commented 7 months ago

Problem Description

Upgraded the version of Instana layer to 175 recently and started getting errors in a lambda which has its own custom layer. The custom layer contains a sharp library which had to be built specifically for x86. From version 171 onwards (170 and below are fine), the lambda keeps erroring with the following error:

{ "errorType": "TypeError", "errorMessage": "LRUCache is not a constructor", "stack": [ "TypeError: LRUCache is not a constructor", " at Object.<anonymous> (/opt/nodejs/node_modules/@instana/core/src/tracing/instrumentation/database/pgNative.js:18:28)", " at Module._compile (node:internal/modules/cjs/loader:1356:14)", " at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)", " at Module.load (node:internal/modules/cjs/loader:1197:32)", " at Module._load (node:internal/modules/cjs/loader:1013:12)", " at Function.patchedModuleLoad [as _load] (/opt/nodejs/node_modules/@instana/core/src/util/requireHook.js:84:34)", " at Module.require (node:internal/modules/cjs/loader:1225:19)", " at require (node:internal/modules/helpers:177:18)", " at /opt/nodejs/node_modules/@instana/core/src/tracing/index.js:197:52", " at Array.forEach (<anonymous>)" ] }

Any insight into this is much appreciated. Thank You

Short, Self Contained Example

No response

Node.js Version

18.16.1

package.json

N/A

package-lock.json

N/A
kirrg001 commented 7 months ago

Thank you for the report. We will take a look asap.

kirrg001 commented 7 months ago

We have updated the lru-cache in our last major release 3.0.0.

Can you please share which version of the LRU cache is installed? Sounds to me the version is still on 6.x 🤔

deepakthankachan commented 7 months ago

I am packaging an npm dependency called sharp into a layer. Not using lru-cache directly in the code. I looked into dependencies of sharp and lru-cache is not listed there.

deepakthankachan commented 7 months ago

Looks like it was using the lru-cache dependency from the custom layer and not the latest one required by Instana. I changed the merge ordering of the layer and it's working now. I will try updating the sharp layer to a newer version to see if it brings in a newer version of lru-cache too but due to how AWS layers load the dependencies, anyone can hit this issue if they have a conflicting dependency in another layer they are using. How are dependencies bundled into the Instana layer?

kirrg001 commented 7 months ago

Glad it's working now :)

How are dependencies bundled into the Instana layer?

There is an extensions folder for our Go application and a node_modules folder (/opt/nodejs/node_modules) containing the provided Instana npm packages. We simply install the dependencies using npm before we publish the layer.

Did you check the NODE_PATH variable? 🤔 I think Node.js is checking first the NODE_PATH and then the current directory.

kirrg001 commented 7 months ago

@deepakthankachan ping

kirrg001 commented 7 months ago

Closing due to inactivity. Feel free to re-open the issue :)