Skip to content

Commit 1d92820

Browse files
authored
Merge pull request #181 from conhealth/fix-pynamodb-with-botocore-1.13
Fix patching for PynamoDB 4.x with botocore 1.13
2 parents dbdeab6 + f1f8cd4 commit 1d92820

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

aws_xray_sdk/ext/pynamodb/patch.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import botocore.vendored.requests.sessions
21
import json
32
import wrapt
43
import pynamodb
@@ -9,20 +8,30 @@
98

109
PYNAMODB4 = int(pynamodb.__version__.split('.')[0]) >= 4
1110

11+
if PYNAMODB4:
12+
import botocore.httpsession
13+
else:
14+
import botocore.vendored.requests.sessions
15+
1216

1317
def patch():
1418
"""Patch PynamoDB so it generates subsegements when calling DynamoDB."""
1519

16-
if hasattr(botocore.vendored.requests.sessions, '_xray_enabled'):
17-
return
18-
setattr(botocore.vendored.requests.sessions, '_xray_enabled', True)
19-
2020
if PYNAMODB4:
21+
if hasattr(botocore.httpsession, '_xray_enabled'):
22+
return
23+
setattr(botocore.httpsession, '_xray_enabled', True)
24+
2125
module = 'botocore.httpsession'
2226
name = 'URLLib3Session.send'
2327
else:
28+
if hasattr(botocore.vendored.requests.sessions, '_xray_enabled'):
29+
return
30+
setattr(botocore.vendored.requests.sessions, '_xray_enabled', True)
31+
2432
module = 'botocore.vendored.requests.sessions'
2533
name = 'Session.send'
34+
2635
wrapt.wrap_function_wrapper(
2736
module, name, _xray_traced_pynamodb,
2837
)

0 commit comments

Comments
 (0)