4
4
# Copyright 2019 Datadog, Inc.
5
5
6
6
import sys
7
+ import logging
7
8
8
9
from wrapt import wrap_function_wrapper as wrap
9
10
10
11
from datadog_lambda .tracing import get_dd_trace_context
11
12
13
+ logger = logging .getLogger (__name__ )
14
+
12
15
if sys .version_info >= (3 , 0 , 0 ):
13
16
httplib_module = 'http.client'
14
17
else :
15
18
httplib_module = 'httplib'
16
19
17
20
_httplib_patched = False
18
21
_requests_patched = False
19
- _botocore_requests_patched = False
20
22
21
23
22
24
def patch_all ():
@@ -26,7 +28,6 @@ def patch_all():
26
28
"""
27
29
_patch_httplib ()
28
30
_patch_requests ()
29
- _patch_botocore_requests ()
30
31
31
32
32
33
def _patch_httplib ():
@@ -42,6 +43,7 @@ def _patch_httplib():
42
43
'HTTPConnection.request' ,
43
44
_wrap_httplib_request
44
45
)
46
+ logger .debug ('Patched %s' , httplib_module )
45
47
46
48
47
49
def _patch_requests ():
@@ -58,26 +60,9 @@ def _patch_requests():
58
60
'Session.request' ,
59
61
_wrap_requests_request
60
62
)
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 )
81
66
82
67
83
68
def _wrap_requests_request (func , instance , args , kwargs ):
0 commit comments