diff --git a/sentry_sdk/integrations/aws_lambda.py b/sentry_sdk/integrations/aws_lambda.py index 6dad75076c..593c93c7ad 100644 --- a/sentry_sdk/integrations/aws_lambda.py +++ b/sentry_sdk/integrations/aws_lambda.py @@ -453,6 +453,11 @@ def event_processor( ip = identity.get("sourceIp") if ip is not None: user_info.setdefault("ip_address", ip) + + if "incoming_request" in client_options["data_collection"]["http_bodies"]: + if "body" in aws_event: + request["data"] = aws_event.get("body", "") + elif should_send_default_pii(): user_info = sentry_event.setdefault("user", {}) diff --git a/tests/integrations/aws_lambda/test_aws_lambda.py b/tests/integrations/aws_lambda/test_aws_lambda.py index 02be52e69e..d91189a2a6 100644 --- a/tests/integrations/aws_lambda/test_aws_lambda.py +++ b/tests/integrations/aws_lambda/test_aws_lambda.py @@ -530,7 +530,7 @@ def test_request_data_with_data_collection_allowlist(lambda_client, test_environ "userArn": "42" } }, - "body": null, + "body": "{\\"toy\\": \\"tennisball\\"}", "isBase64Encoded": false } """ @@ -560,6 +560,7 @@ def test_request_data_with_data_collection_allowlist(lambda_client, test_environ "method": "GET", "query_string": {"bonkers": "true"}, "url": "https://iwsz2c7uwi.execute-api.us-east-1.amazonaws.com/asd", + "data": '{"toy": "tennisball"}', } @@ -588,7 +589,7 @@ def test_request_data_with_data_collection_denylist(lambda_client, test_environm "userArn": "42" } }, - "body": null, + "body": "{\\"toy\\": \\"tennisball\\"}", "isBase64Encoded": false } """ @@ -617,6 +618,7 @@ def test_request_data_with_data_collection_denylist(lambda_client, test_environm "method": "GET", "query_string": {"bonkers": "true"}, "url": "https://iwsz2c7uwi.execute-api.us-east-1.amazonaws.com/asd", + "data": '{"toy": "tennisball"}', } @@ -644,7 +646,7 @@ def test_request_data_with_data_collection_off(lambda_client, test_environment): "userArn": "42" } }, - "body": null, + "body": "{\\"toy\\": \\"tennisball\\"}", "isBase64Encoded": false } """ @@ -663,6 +665,7 @@ def test_request_data_with_data_collection_off(lambda_client, test_environment): "method": "GET", "query_string": {"bonkers": "true"}, "url": "https://iwsz2c7uwi.execute-api.us-east-1.amazonaws.com/asd", + "data": '{"toy": "tennisball"}', }