Open SidPrak7 opened 3 weeks ago
Hi @SidPrak7 thanks for writing in!
Our layer auto init script is currently only exported for CJS which is why you're running into these errors with your function which is running in ESM. I'm gonna take a look at adding an ESM entry point for this. Can't promise that this will work easily because ESM is a mess but I'll leave an update or PR later.
try:
import Sentry from '@sentry/aws-serverless';
So, I looked into emitting an ESM version of the lambda layer a bit today and as expected it wasn't as straight forward as I hoped 🥲
Some challenges we overcame or still need to figure out:
awslambda-auto.js
in ESMrequire
references with a minified version of require
that just throws an error 🤦 We can fix this. Found an ugly way so far but there's probably a nicer solution.--import
arg set in NODE_OPTIONS
. I'm not sure yet what the cause is. So far, my two suspicions are:
http
that are evaluated before the init
call is madehttp
et al. not being patchedI'll work on this a bit more tomorrow. For now, to unblock you, I can't give you a better workaround yet than to run your lambdas in CJS ("require") mode. If you're building/transpiling your functions (e.g. typescript) this shouldn't be too hard; otherwise rewriting everything to require instead of import is obviously not ideal. I'll keep you posted on updates.
EDIT: Actually, one thing I haven't tried so far is to directly import and use the @sentry/aws-serverless
package in your functions, as shown here, without using our layer at all. This should work and I know it does fine in CJS. However, I haven't tested this yet in ESM.
Hi, I have the same issue, tried multiple options as described.
Using NODE_OPTIONS="-r @sentry/aws-serverless/awslambda-auto"
seems to make AWS happy, but nothing is logged on Sentry's side and importing the actual layer within ESM code does not work.
nothing is logged on Sentry's side
@tgdn I think this is a different problem than the one described in this issue (which is about running the lambda layer in ESM mode). if you run your lambda function as CJS (i.e. require
syntax) and you're experiencing problems, would you mind opening a new issue? Thanks :)
@Lms24 I didn't mention it but I'm also running the lambda layer in ESM mode :)
The only alternative seems to be importing Sentry and using Sentry.wrapHandler()
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/aws-serverless
SDK Version
8.7.0
Framework Version
@sentry/aws-serverless
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
We tried the full combination set of these steps.
arn:aws:lambda:us-west-2:943013980633:layer:SentryNodeServerlessSDK:247
arn:aws:lambda:us-west-2:943013980633:layer:SentryNodeServerlessSDKv7:1
We also manually built a layer and pushed it to the λ
SENTRY_DSN='SENTRY_DSN'
SENTRY_TRACES_SAMPLE_RATE=1
These four variations of
NODE_OPTIONS
:NODE_OPTIONS='-r @sentry/serverless/dist/awslambda-auto'
NODE_OPTIONS='-r @sentry/serverless/awslambda-auto'
NODE_OPTIONS='-r @sentry/aws-serverless/build/npm/cjs/awslambda-auto'
not setting NODE_OPTIONSIt might be relevant that our file is
.mjs
file.We are only noting the relevant errors in the Actual Result section.
Expected Result
Sentry logs something.
Actual Result
For the v7 arn & node options with dist in it:
For the v7 arn & node options without dist in it:
For the arn we got from the docs & node options with
dist
in it:For the arn we got from the docs & node options without
dist
in it:For the arn we got from the docs & node options with
cjs
in it:Also, since the official docs for loading the layer didn't specify setting NODE_OPTIONS, we also tried that: