From 97be9d86df9e8f7691438cb8c72a37b2295f4f2e Mon Sep 17 00:00:00 2001 From: j4y-m Date: Sun, 11 Dec 2022 10:06:36 +0100 Subject: [PATCH] doc(awslambda/captureAllSettledReasons/contextBuilderFn) : Add documentation : Build specific context for each captured promises - Related MR : https://github.com/getsentry/sentry-javascript/pull/6492 --- .../node/guides/aws-lambda/index.mdx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/platforms/node/guides/aws-lambda/index.mdx b/src/platforms/node/guides/aws-lambda/index.mdx index a893bb32acb714..f1477084558150 100644 --- a/src/platforms/node/guides/aws-lambda/index.mdx +++ b/src/platforms/node/guides/aws-lambda/index.mdx @@ -108,6 +108,37 @@ exports.handler = Sentry.AWSLambda.wrapHandler( // `first` and `second` errors are captured ``` +### Build a context according to the exception raised + +_(New in version ??)_ + +It is possible to pass a `contextBuilderFn` function which allows to build a SentryContext +according to the error raised by `captureAllSettledReasons`. + +```javascript {tabTitle:captureAllSettledReasons} +exports.handler = Sentry.AWSLambda.wrapHandler( + () => { + return Promise.allSettled([ + Promise.rejected(new Error("first")), + Promise.rejected(new Error("second")), + ]); + }, + { + captureAllSettledReasons: { + contextBuilderFn: ( + event: SQSEvent | YourLambdaEvent, + reason: Error, + allSettledResultIndex: number + ) => { + return { tags: { errorMessage: reason.message } }; + }, + }, + } +); +// `first` and `second` errors are captured, +// the event on sentry will be tagged with the error message (first and second) +``` + ## Behavior With the AWS Lambda integration enabled, the Node SDK will: