What happened?
I am trying to instrument ESM lambdas using the ESM support feature added in #3698 and the feature is not working in the lambda environment.
Steps to Reproduce
- Deploy an ESM node lambda using serverless.
- I am using Splunk's opentelemetry layer to instrument the lambda which internally uses opentelemetry-js for the instrumentation.
- Made sure to pre-load
@opentelemetry/instrumentation/hook.mjs in the lambda wrapper.
Expected Result
The lambda should be instrumented and should send traces to the collector.
Actual Result
We are not seeing any traces being sent to the collector.
Additional Details
I reckon there's an issue with import-in-the-middle which internally uses module-details-from-path's parse method to get the baseDir value. It requires modules to be in a node_modules directory to work.
We are getting undefiend for the baseDire value in the hookfn here.
And since the baseDir is undefined, the _onRequire method unexpectedly returns from here.
OpenTelemetry Setup Code
AWS_LAMBDA_EXEC_WRAPPER: nodejs-otel-handler
#!/bin/bash
source /opt/splunk-default-config
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js --experimental-loader=/opt/nodejs/node_modules/@opentelemetry/instrumentation/hook.mjs"
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"
fi
exec "$@"
Splunk's Otel wrapper, https://github.com/signalfx/splunk-otel-lambda/blob/main/nodejs/src/wrapper.ts
package.json
No response
Relevant log output
No response
What happened?
I am trying to instrument ESM lambdas using the ESM support feature added in #3698 and the feature is not working in the lambda environment.
Steps to Reproduce
@opentelemetry/instrumentation/hook.mjsin the lambda wrapper.Expected Result
The lambda should be instrumented and should send traces to the collector.
Actual Result
We are not seeing any traces being sent to the collector.
Additional Details
I reckon there's an issue with
import-in-the-middlewhich internally usesmodule-details-from-path's parse method to get thebaseDirvalue. It requires modules to be in a node_modules directory to work.We are getting
undefiendfor thebaseDirevalue in thehookfnhere.And since the
baseDirisundefined, the_onRequiremethod unexpectedly returns from here.OpenTelemetry Setup Code
Splunk's Otel wrapper, https://github.com/signalfx/splunk-otel-lambda/blob/main/nodejs/src/wrapper.ts
package.json
No response
Relevant log output
No response