Skip to content

Commit 2423299

Browse files
itsbjoernantonpirker
andauthoredFeb 20, 2025··
AWS Lambda: Fix capturing errors during AWS Lambda INIT phase (#3943)
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 <[email protected]>
1 parent 4d64c4e commit 2423299

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

Diff for: ‎sentry_sdk/integrations/aws_lambda.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ def sentry_init_error(*args, **kwargs):
6161

6262
else:
6363
# Fall back to AWS lambdas JSON representation of the error
64-
sentry_event = _event_from_error_json(json.loads(args[1]))
64+
error_info = args[1]
65+
if isinstance(error_info, str):
66+
error_info = json.loads(error_info)
67+
sentry_event = _event_from_error_json(error_info)
6568
sentry_sdk.capture_event(sentry_event)
6669

6770
return init_error(*args, **kwargs)

Diff for: ‎tests/integrations/aws_lambda/test_aws.py

-3
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ def test_handler(event, context):
316316
}
317317

318318

319-
@pytest.mark.xfail(
320-
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."
321-
)
322319
def test_init_error(run_lambda_function, lambda_runtime):
323320
envelope_items, _ = run_lambda_function(
324321
LAMBDA_PRELUDE

0 commit comments

Comments
 (0)
Please sign in to comment.