You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
exportconsthandler=()=>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 build in the nodejs directory. This produces a layer.zip file.
Upload layer.zip as 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_WRAPPER to /opt/otel-handler.
Locally, create index.js as
exportconsthandler=()=>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
The text was updated successfully, but these errors were encountered:
Unfortunately, this is the limitation of the shimmer which is the library OTEL JS SDK uses for monkey patching to instrument user handler. esbuild generate immutable objects which are not writeable and this is the point where shimmer fails.
I was actually able to get this to work in my real codebase by converting my handler files to CommonJS modules. My code is still able to use the import syntax, even though it is CommonJS (I did not realize that was possible). All of my non-handler files are still in ES Modules.
Describe the bug
The Node.js layer is working correctly when using a handwritten CommonJS handler like this:
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.
Now, the Lambda fails with the error
Steps to reproduce
npm run build
in thenodejs
directory. This produces alayer.zip
file.layer.zip
as a layer via the AWS Console.AWS_LAMBDA_EXEC_WRAPPER
to/opt/otel-handler
.index.js
asnpx esbuild index.js --platform=node --bundle --outfile=compiled.js
. View the compiled bundle hereWhat did you expect to see?
The Lambda succeeds.
What did you see instead?
The Lambda fails with the error
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
The text was updated successfully, but these errors were encountered: