From 25c79a2137e01cbc7678b7ca44c3bbfbac46c016 Mon Sep 17 00:00:00 2001 From: Antonio Zaitoun Date: Wed, 16 Apr 2025 19:20:51 +0300 Subject: [PATCH 1/2] Update patch.py for requests Patching the `send` function instead of `request` (this achieves the same affect) --- aws_xray_sdk/ext/requests/patch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_xray_sdk/ext/requests/patch.py b/aws_xray_sdk/ext/requests/patch.py index 66e7ef81..c09860bf 100644 --- a/aws_xray_sdk/ext/requests/patch.py +++ b/aws_xray_sdk/ext/requests/patch.py @@ -9,7 +9,7 @@ def patch(): wrapt.wrap_function_wrapper( 'requests', - 'Session.request', + 'Session.send', _xray_traced_requests ) @@ -22,7 +22,7 @@ def patch(): def _xray_traced_requests(wrapped, instance, args, kwargs): - url = kwargs.get('url') or args[1] + url = args[1].url return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, From 76e1cd25410ceb945b2ae4fbb4b858d3dfa92cc6 Mon Sep 17 00:00:00 2001 From: Antonio Zaitoun Date: Wed, 16 Apr 2025 19:40:31 +0300 Subject: [PATCH 2/2] Fixed requests patch issue --- aws_xray_sdk/ext/requests/patch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aws_xray_sdk/ext/requests/patch.py b/aws_xray_sdk/ext/requests/patch.py index 66e7ef81..cff0c9ad 100644 --- a/aws_xray_sdk/ext/requests/patch.py +++ b/aws_xray_sdk/ext/requests/patch.py @@ -6,10 +6,9 @@ def patch(): - wrapt.wrap_function_wrapper( 'requests', - 'Session.request', + 'Session.send', _xray_traced_requests ) @@ -22,7 +21,7 @@ def patch(): def _xray_traced_requests(wrapped, instance, args, kwargs): - url = kwargs.get('url') or args[1] + url = args[0].url return xray_recorder.record_subsegment( wrapped, instance, args, kwargs, @@ -43,9 +42,10 @@ def _inject_header(wrapped, instance, args, kwargs): def requests_processor(wrapped, instance, args, kwargs, return_value, exception, subsegment, stack): - - method = kwargs.get('method') or args[0] - url = kwargs.get('url') or args[1] + + request = args[0] + method = request.method + url = request.url subsegment.put_http_meta(http.METHOD, method) subsegment.put_http_meta(http.URL, strip_url(url))