-
Notifications
You must be signed in to change notification settings - Fork 234
Closed as not planned
open-telemetry/opentelemetry-js-contrib
#3422Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The Node.js layer is working correctly when using a handwritten CommonJS handler like this:
module.exports = {
handler: () => 200
}My real code is written in ES Modules and is bundled via esbuild. Compile the following code with esbuild and then deploy it to Lambda.
export const handler = () => 200;Now, the Lambda fails with the error
{
"errorType": "TypeError",
"errorMessage": "Cannot redefine property: handler",
"stack": [
"TypeError: Cannot redefine property: handler",
" at Function.defineProperty (<anonymous>)",
" at n (/opt/wrapper.js:1:242970)",
" at i (/opt/wrapper.js:1:243369)",
" at o._wrap (/opt/wrapper.js:1:252372)",
" at x.patch (/opt/wrapper.js:1:204436)",
" at /opt/wrapper.js:1:254659",
" at Array.reduce (<anonymous>)",
" at t._onRequire (/opt/wrapper.js:1:254445)",
" at t (/opt/wrapper.js:1:255685)",
" at Module.T (/opt/wrapper.js:1:92076)"
]
}
Steps to reproduce
- Clone the opentelemetry-lambda repo and execute
npm run buildin thenodejsdirectory. This produces alayer.zipfile. - Upload
layer.zipas a layer via the AWS Console. - Create a new Lambda function (Node.js 22.x) and add the layer to it.
- In the environment variables for the Lambda, set
AWS_LAMBDA_EXEC_WRAPPERto/opt/otel-handler. - Locally, create
index.jsasexport const handler = () => 200;
- Bundle the code using esbuild by running
npx esbuild index.js --platform=node --bundle --outfile=compiled.js. View the compiled bundle here - Paste the compiled code into the code editor for the Lambda function in the AWS Console. Click "Deploy".
- In the AWS Console, test the Lambda function with an arbitrary payload.
What did you expect to see?
The Lambda succeeds.
What did you see instead?
The Lambda fails with the error
{
"errorType": "TypeError",
"errorMessage": "Cannot redefine property: handler",
"stack": [
"TypeError: Cannot redefine property: handler",
" at Function.defineProperty (<anonymous>)",
" at n (/opt/wrapper.js:1:242970)",
" at i (/opt/wrapper.js:1:243369)",
" at o._wrap (/opt/wrapper.js:1:252372)",
" at x.patch (/opt/wrapper.js:1:204436)",
" at /opt/wrapper.js:1:254659",
" at Array.reduce (<anonymous>)",
" at t._onRequire (/opt/wrapper.js:1:254445)",
" at t (/opt/wrapper.js:1:255685)",
" at Module.T (/opt/wrapper.js:1:92076)"
]
}
What version of collector/language SDK version did you use?
I cloned the opentelemetry-lambda repo, and the latest commit on main was 939cecd.
What language layer did you use?
Node.js
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working