44# Copyright 2019 Datadog, Inc.
55
66import sys
7+ import logging
78
89from wrapt import wrap_function_wrapper as wrap
910
1011from datadog_lambda .tracing import get_dd_trace_context
1112
13+ logger = logging .getLogger (__name__ )
14+
1215if sys .version_info >= (3 , 0 , 0 ):
1316 httplib_module = 'http.client'
1417else :
1518 httplib_module = 'httplib'
1619
1720_httplib_patched = False
1821_requests_patched = False
19- _botocore_requests_patched = False
2022
2123
2224def patch_all ():
@@ -26,7 +28,6 @@ def patch_all():
2628 """
2729 _patch_httplib ()
2830 _patch_requests ()
29- _patch_botocore_requests ()
3031
3132
3233def _patch_httplib ():
@@ -42,6 +43,7 @@ def _patch_httplib():
4243 'HTTPConnection.request' ,
4344 _wrap_httplib_request
4445 )
46+ logger .debug ('Patched %s' , httplib_module )
4547
4648
4749def _patch_requests ():
@@ -58,26 +60,9 @@ def _patch_requests():
5860 'Session.request' ,
5961 _wrap_requests_request
6062 )
61- except ImportError :
62- pass
63-
64-
65- def _patch_botocore_requests ():
66- """
67- Patch the `requests` module that is packaged into `botocore`.
68- https://stackoverflow.com/questions/40741282/cannot-use-requests-module-on-aws-lambda
69- """
70- global _botocore_requests_patched
71- if not _botocore_requests_patched :
72- _botocore_requests_patched = True
73- try :
74- wrap (
75- 'botocore.vendored.requests' ,
76- 'Session.request' ,
77- _wrap_requests_request
78- )
79- except ImportError :
80- pass
63+ logger .debug ('Patched requests' )
64+ except Exception :
65+ logger .debug ('Failed to patch requests' , exc_info = True )
8166
8267
8368def _wrap_requests_request (func , instance , args , kwargs ):
0 commit comments