Skip to content

Commit

Permalink
AWS Lambda: Fix capturing errors during AWS Lambda INIT phase (#3943)
Browse files Browse the repository at this point in the history
The AWS integration fails to capture errors during the INIT phase (at least in Python 3.8 and above environments).

It appears tests for this were disabled after a change in AWS' own runtime environment: #3592

A change from a few months ago where it seems like string serialisation of the JSON payload was disabled and instead the `post_init_error` is invoked directly with the json payload: aws/aws-lambda-python-runtime-interface-client@a37a43a#diff-4513a869520b19ae4e30058106d7c3b5ddbb79216b5e9bd922d83389fb86c603R483

This breaks and causes an error internally when trying to parse the string back into json, and the error is actually swallowed because of `with capture_internal_exceptions()`.

Co-authored-by: Anton Pirker <anton.pirker@sentry.io>
  • Loading branch information
itsbjoern and antonpirker authored Feb 20, 2025
1 parent 4d64c4e commit 2423299
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sentry_sdk/integrations/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def sentry_init_error(*args, **kwargs):

else:
# Fall back to AWS lambdas JSON representation of the error
sentry_event = _event_from_error_json(json.loads(args[1]))
error_info = args[1]
if isinstance(error_info, str):
error_info = json.loads(error_info)
sentry_event = _event_from_error_json(error_info)
sentry_sdk.capture_event(sentry_event)

return init_error(*args, **kwargs)
Expand Down
3 changes: 0 additions & 3 deletions tests/integrations/aws_lambda/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ def test_handler(event, context):
}


@pytest.mark.xfail(
reason="Amazon changed something (2024-10-01) and on Python 3.9+ our SDK can not capture events in the init phase of the Lambda function anymore. We need to fix this somehow."
)
def test_init_error(run_lambda_function, lambda_runtime):
envelope_items, _ = run_lambda_function(
LAMBDA_PRELUDE
Expand Down

0 comments on commit 2423299

Please sign in to comment.