Skip to content

Fix patching for PynamoDB 4.x with botocore 1.13 #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions aws_xray_sdk/ext/pynamodb/patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import botocore.vendored.requests.sessions
import json
import wrapt
import pynamodb
Expand All @@ -9,20 +8,30 @@

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

if PYNAMODB4:
import botocore.httpsession
else:
import botocore.vendored.requests.sessions


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

if hasattr(botocore.vendored.requests.sessions, '_xray_enabled'):
return
setattr(botocore.vendored.requests.sessions, '_xray_enabled', True)

if PYNAMODB4:
if hasattr(botocore.httpsession, '_xray_enabled'):
return
setattr(botocore.httpsession, '_xray_enabled', True)

module = 'botocore.httpsession'
name = 'URLLib3Session.send'
else:
if hasattr(botocore.vendored.requests.sessions, '_xray_enabled'):
return
setattr(botocore.vendored.requests.sessions, '_xray_enabled', True)

module = 'botocore.vendored.requests.sessions'
name = 'Session.send'

wrapt.wrap_function_wrapper(
module, name, _xray_traced_pynamodb,
)
Expand Down