Skip to content

Can not use ESM support in lambda environment  #4842

@nikhileshcr-splunk

Description

@nikhileshcr-splunk

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

  1. Deploy an ESM node lambda using serverless.
  2. I am using Splunk's opentelemetry layer to instrument the lambda which internally uses opentelemetry-js for the instrumentation.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p2Bugs and spec inconsistencies which cause telemetry to be incomplete or incorrecttriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions