Asynchronously detects if the Lambda library is installed both in node_modules and as a Lambda library. If so, it logs a warning.
Motivation
It's common for users to install the Lambda layers as instructed by the documentation, but then then see import errors in their code, causing them to run npm install datadog-lambda-js. Now they will have the Lambda library installed in two places, which will (1) increase package size and cold start duration, and (2) break custom metrics.
We've had several customers open support tickets recently about broken metrics caused by this issue, so this PR aims to avoid this problem in the future.
Testing Guidelines
Manual tests: logs a warning as expected when installed in both places, and doesn't log any warning if only installed in the layer or node_modules.
Added unit tests.
Additional Notes
This works by using fs and checking if the paths exist. I'm assuming the paths will always be:
There is probably a "better" solution if we use process.env.NODE_PATH and search for datadog-lambda-js/package.json in the paths. However, my solution is simpler and works perfectly fine. It should have less overhead since we don't have to parse the node path.
What does this PR do?
Asynchronously detects if the Lambda library is installed both in node_modules and as a Lambda library. If so, it logs a warning.
Motivation
It's common for users to install the Lambda layers as instructed by the documentation, but then then see import errors in their code, causing them to run npm install datadog-lambda-js. Now they will have the Lambda library installed in two places, which will (1) increase package size and cold start duration, and (2) break custom metrics.
We've had several customers open support tickets recently about broken metrics caused by this issue, so this PR aims to avoid this problem in the future.
Testing Guidelines
Manual tests: logs a warning as expected when installed in both places, and doesn't log any warning if only installed in the layer or node_modules.
Added unit tests.
Additional Notes
This works by using
fs
and checking if the paths exist. I'm assuming the paths will always be:'/opt/nodejs/node_modules/datadog-lambda-js'
path.join(process.cwd(), 'node_modules/datadog-lambda-js')
There is probably a "better" solution if we use
process.env.NODE_PATH
and search fordatadog-lambda-js/package.json
in the paths. However, my solution is simpler and works perfectly fine. It should have less overhead since we don't have to parse the node path.Types of Changes
Check all that apply