Skip to content

Commit 1496b6f

Browse files
committed
docs: update sentry section
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
1 parent 27f2937 commit 1496b6f

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

docs/utilities/batch.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,33 @@ Use the context manager to access a list of all returned values from your `recor
769769

770770
Use context manager when you want access to the processed messages or handle `BatchProcessingError` exception when all records within the batch fail to be processed.
771771

772+
### Integrating exception handling with Sentry.io
773+
774+
When using Sentry.io for error monitoring, you can override `failure_handler` to capture each processing exception with Sentry SDK:
775+
776+
> Credits to [Charles-Axel Dein](https://github.com/awslabs/aws-lambda-powertools-python/issues/293#issuecomment-781961732)
777+
778+
=== "sentry_integration.py"
779+
780+
```python hl_lines="4 7-8"
781+
from typing import Tuple
782+
783+
from aws_lambda_powertools.utilities.batch import BatchProcessor, FailureResponse
784+
from sentry_sdk import capture_exception
785+
786+
787+
class MyProcessor(BatchProcessor):
788+
def failure_handler(self, record, exception) -> FailureResponse:
789+
capture_exception() # send exception to Sentry
790+
return super().failure_handler(record, exception)
791+
```
792+
793+
794+
## Legacy
795+
796+
!!! tip "This is kept for historical purposes. Use the new [BatchProcessor](#processing-messages-from-sqs) instead. "
772797

773-
<!-- ### Customizing boto configuration
798+
### Customizing boto configuration
774799

775800
The **`config`** and **`boto3_session`** parameters enable you to pass in a custom [botocore config object](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html)
776801
or a custom [boto3 session](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html) when using the `sqs_batch_processor`
@@ -868,9 +893,9 @@ decorator or `PartialSQSProcessor` class.
868893
result = processor.process()
869894

870895
return result
871-
``` -->
896+
```
872897

873-
<!-- ### Suppressing exceptions
898+
### Suppressing exceptions
874899

875900
If you want to disable the default behavior where `SQSBatchProcessingError` is raised if there are any errors, you can pass the `suppress_exception` boolean argument.
876901

@@ -893,9 +918,9 @@ If you want to disable the default behavior where `SQSBatchProcessingError` is r
893918

894919
with processor(records, record_handler):
895920
result = processor.process()
896-
``` -->
921+
```
897922

898-
<!-- ### Create your own partial processor
923+
### Create your own partial processor
899924

900925
You can create your own partial batch processor by inheriting the `BasePartialProcessor` class, and implementing `_prepare()`, `_clean()` and `_process_record()`.
901926

@@ -968,24 +993,3 @@ You can then use this class as a context manager, or pass it to `batch_processor
968993
def lambda_handler(event, context):
969994
return {"statusCode": 200}
970995
```
971-
972-
### Integrating exception handling with Sentry.io
973-
974-
When using Sentry.io for error monitoring, you can override `failure_handler` to include to capture each processing exception:
975-
976-
> Credits to [Charles-Axel Dein](https://github.com/awslabs/aws-lambda-powertools-python/issues/293#issuecomment-781961732)
977-
978-
=== "sentry_integration.py"
979-
980-
```python hl_lines="4 7-8"
981-
from typing import Tuple
982-
983-
from aws_lambda_powertools.utilities.batch import PartialSQSProcessor
984-
from sentry_sdk import capture_exception
985-
986-
class SQSProcessor(PartialSQSProcessor):
987-
def failure_handler(self, record: Event, exception: Tuple) -> Tuple: # type: ignore
988-
capture_exception() # send exception to Sentry
989-
logger.exception("got exception while processing SQS message")
990-
return super().failure_handler(record, exception) # type: ignore
991-
``` -->

0 commit comments

Comments
 (0)