Sentry.wrapHandler() not optional when using @sentry/serverless-aws but docs suggest it is
Closed this issue ยท 6 comments
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/aws-serverless
SDK Version
10.15.0
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
https://github.com/callumgare/sentry-lambda-http-proxy-issue
Steps to Reproduce
The sentry docs seem to indicate that you can throw an error and have it reported to Sentry without using
Sentry.wrapHandler():
- https://docs.sentry.io/platforms/javascript/guides/aws-lambda/#verify
- https://github.com/getsentry/sentry-javascript/blob/be0c75da49bb761d8163ae14f6e7a1e662680059/packages/aws-serverless/README.md
But as best as I can tell this doesn't seem to be the case. If you deploy the code in the reproduction repo without the USE_SENTRY_WRAPPER env var set so Sentry.wrapHandler() isn't used and send a request to the function url then you should see the error "This always gets reported" in sentry but not the error "This only gets reported if using Sentry.wrapHandler()". Redeploying again with USE_SENTRY_WRAPPER set to true you should now see both.
Expected Result
I would expect the thrown error to be reported (or the docs to indicate that Sentry.wrapHandler()` is required to receive thrown errors).
Actual Result
Following the steps to reproduce you should see something like this:

(note the event count)
Additional Context
Tip: React with ๐ to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Hi @callumgare, thanks for writing in and providing a reproduction repo.
For the auto-wrapping to work, you need to initialize Sentry in its own file and --import it, otherwise we can't automatically instrument and wrap your handler.
If you're not using our AWS Lambda Layer please see: https://docs.sentry.io/platforms/javascript/guides/aws-lambda/install/npm/#option-b-manual-setup
Could you try that and see if you still have that issue?
That did it! (I've added a branch that modifies the reproduction repo for posterity https://github.com/callumgare/sentry-lambda-http-proxy-issue/tree/fix)
Thanks very much ๐
It might be good to update https://github.com/getsentry/sentry-javascript/blob/be0c75da49bb761d8163ae14f6e7a1e662680059/packages/aws-serverless/README.md in that case. Since the code snippet in that makes it look like you can call Sentry.init() in the handler file without the use of Sentry.wrapHandler().
Ah yea, that README is definitely misleading. Thanks for bringing that up!
Is this something you might want to contribute? No pressure tho, we will take care of it otherwise.
Beat me to it! Thanks very much for that @andreiborza :)
A PR closing this issue has just been released ๐
This issue was referenced by PR #17787, which was included in the 10.16.0 release.