Closed anthonyc4 closed 1 year ago
@mrickard I transferred this from newrelic-lambda-extension
.
@anthonyc4 This was an enhancement we investigated, and unfortunately there's a fundamental blocker: NODE_PATH
is not used in resolving import
specifiers. See the Node ESM docs for this.
The no-code-change instrumentation we have leverages AWS's layers standard for installing our agent in /opt/nodejs
while being able to instrument dependencies in /var/task
, finding them by using NODE_PATH
. Without an ambient path available, the agent in /opt/nodejs
can't find your dependencies or handler.
While that rules out using the Lambda Layer, you can still instrument ESM Lambda functions with New Relic, by following these instructions.
Description
good morning....
We are using New Relic's Lambda Extension (layer) to report metrics back to NR. Everything is working great....
We now want to migrate our Node14 Lambdas from commonjs to esm . The lambdas are working well as ESM but as soon as I change the handler to newrelic-lambda-wrapper.handler to go through the New Relic Lambda Extension instead of directly (testEsm.default), the lambda fails.
Judging by the errors, it seems like it is using a cjs loader to try to load the default handler testEsm.default for instance and it says it does not exist.
Has anyone run into this and is there a way to use the New Relic Lambda Extension with ESM build NodeJs14 modules?
If this is the wrong channel, please let me know....
Steps to Reproduce
testEsm.default
) tonewrelic-lambda-wrapper.handler
NEW_RELIC_LAMBDA_EXTENSION_ENABLED
NEW_RELIC_LAMBDA_HANDLER
(set to `testEsm.default in our case)NEW_RELIC_ACCOUNT_ID
set to our accountIn cloudFormation when deploying, you will receive
Provisioned Concurrency configuration failed to be applied. Reason: FUNCTION_ERROR_INIT_FAILURE
. If you do this manually via the console, you will seeWe are using this layer:
arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS14X:42
Expected Behavior
The default entry point should work through the Extension as it does if specified directly as the Handler. Changing the handler to
testEsm.default
in our case the lambda works when testing on the console.Relevant Logs / Console output
Your Environment
mjs
extension.Additional context
NOTE: logger/logger is code to add data to console.log in a structured format. It is bundled with
esbuild
when deploying the lambda.