bugsnag / bugsnag-python

Official BugSnag error monitoring and error reporting for django, flask, tornado and other python apps.
https://docs.bugsnag.com/platforms/python/
MIT License
84 stars 42 forks source link

Add `aws_lambda_handler` decorator to Client #378

Closed imjoehaines closed 5 months ago

imjoehaines commented 5 months ago

Goal

This PR adds a decorator that wraps an AWS Lambda handler that:

  1. reports any errors raised by the handler
  2. creates a session for the function invocation
  3. adds the event and context parameters as metadata, under the names "AWS Lambda Event" and `AWS Lambda Context"
  4. waits for outstanding event and session requests to finish before allowing the lambda to exit (with a timeout of 2 seconds by default)

Usage:

@bugsnag.aws_lambda_handler
def my_handler(event, context):
    pass

The maximum time to wait for events and sessions to be delivered is configurable with the flush_timeout_ms parameter:

@bugsnag.aws_lambda_handler(flush_timeout_ms=1000)
def my_handler(event, context):
    pass