getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
8.02k stars 1.59k forks source link

Not receiving issue notifications when using AWS Lambda's Streaming Functionality #8868

Open krishna-cactus opened 1 year ago

krishna-cactus commented 1 year ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/serverless

SDK Version

7.64.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

const Sentry = require("@sentry/serverless"); Sentry.AWSLambda.init({ dsn: "https://abc.com/9", tracesSampleRate: 1.0, environment: "test" }); exports.handler = awslambda.streamifyResponse(async (event, responseStream, _context) => { // Code goes here });

Steps to Reproduce

  1. AWS Lambda has provided support for streaming: https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/

  2. Automatic capturing all exceptions is not throwing issue notifications while if you use "Sentry.captureException("From KM");" it works.

Expected Result

All unhandled exceptions (for example console.logsssss("abc")) should result in sentry notification.

Actual Result

Only handled exceptions are creating notfications, not unhandled ones.

lforst commented 1 year ago

Hi, you need to wrap your handler with the Sentry instrumentation as the docs suggest: https://docs.sentry.io/platforms/node/guides/aws-lambda/

The reason is that lambdas freeze execution as soon as a response is sent (i.e. the handler is done/crashed or a response is finished) and our wrapper defers sending a response until the event is flushed.

We don't officially support streamifyResponse yet so you might need to implement some custom wrapper for your use case.

krishna-cactus commented 1 year ago

Thank you for response @Iforst.

Any custom wrapper that you can recommend?

lforst commented 1 year ago

@krishna-cactus You can take inspiration from our own implementation: https://github.com/getsentry/sentry-javascript/blob/61450cb02dde34b59dedeb3cbd44a690c516e9d5/packages/serverless/src/awslambda.ts#L211