Skip to content

Commit a623415

Browse files
authored
docs(awslambda): Add workaround for unhandledRejection for AWS Lambda (#11380)
1 parent 40d437e commit a623415

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/platforms/javascript/common/configuration/integrations/unhandledrejection.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ This integration is enabled by default. If you'd like to modify your default int
3636

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

39+
40+
<PlatformSection supported={["javascript.aws-lambda"]}>
41+
42+
## On AWS Lambda
43+
44+
AWS adds their own `unhandledRejection` handlers to a lambda function which results in Sentry not being able to pick these up.
45+
As a workaround, remove all handlers before initializing Sentry.
46+
47+
Unfortunately, this means the AWS Lambda handler has to be <PlatformLink to="/install/cjs-layer/#alternative-initialize-the-sdk-in-code">manually wrapped</PlatformLink>.
48+
49+
```JavaScript
50+
const Sentry = require("@sentry/aws-serverless");
51+
52+
// Remove `unhandledRejection` handlers set up by AWS so the
53+
// Sentry SDK can capture these
54+
process.removeAllListeners("unhandledRejection");
55+
56+
Sentry.init({
57+
dsn: "___PUBLIC_DSN___"
58+
// Add Tracing by setting tracesSampleRate and adding integration
59+
// Set tracesSampleRate to 1.0 to capture 100% of transactions
60+
// We recommend adjusting this value in production
61+
tracesSampleRate: 1.0,
62+
});
63+
64+
exports.handler = Sentry.wrapHandler(async (event, context) => {
65+
// Your handler code
66+
});
67+
```
68+
69+
</PlatformSection>
70+
3971
## Options
4072

4173
### `mode`

0 commit comments

Comments
 (0)