Skip to content

Commit

Permalink
docs(awslambda): Add workaround for unhandledRejection for AWS Lamb…
Browse files Browse the repository at this point in the history
…da (#11380)
  • Loading branch information
andreiborza committed Sep 17, 2024
1 parent 40d437e commit a623415
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ This integration is enabled by default. If you'd like to modify your default int

The `onUnhandledRejectionIntegration` registers handlers to capture global unhandled promise rejections.


<PlatformSection supported={["javascript.aws-lambda"]}>

## On AWS Lambda

AWS adds their own `unhandledRejection` handlers to a lambda function which results in Sentry not being able to pick these up.
As a workaround, remove all handlers before initializing Sentry.

Unfortunately, this means the AWS Lambda handler has to be <PlatformLink to="/install/cjs-layer/#alternative-initialize-the-sdk-in-code">manually wrapped</PlatformLink>.

```JavaScript
const Sentry = require("@sentry/aws-serverless");

// Remove `unhandledRejection` handlers set up by AWS so the
// Sentry SDK can capture these
process.removeAllListeners("unhandledRejection");

Sentry.init({
dsn: "___PUBLIC_DSN___"
// Add Tracing by setting tracesSampleRate and adding integration
// Set tracesSampleRate to 1.0 to capture 100% of transactions
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
});

exports.handler = Sentry.wrapHandler(async (event, context) => {
// Your handler code
});
```

</PlatformSection>

## Options

### `mode`
Expand Down

0 comments on commit a623415

Please sign in to comment.