From a6234154688ceb9b6386096692382321a333d126 Mon Sep 17 00:00:00 2001 From: Andrei <168741329+andreiborza@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:01:51 +0200 Subject: [PATCH] docs(awslambda): Add workaround for `unhandledRejection` for AWS Lambda (#11380) --- .../integrations/unhandledrejection.mdx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/platforms/javascript/common/configuration/integrations/unhandledrejection.mdx b/docs/platforms/javascript/common/configuration/integrations/unhandledrejection.mdx index abee9006e0f80..f2039eb73d4f0 100644 --- a/docs/platforms/javascript/common/configuration/integrations/unhandledrejection.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/unhandledrejection.mdx @@ -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. + + + +## 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 manually wrapped. + +```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 +}); +``` + + + ## Options ### `mode`