Skip to content

Commit

Permalink
release commit for 0.96
Browse files Browse the repository at this point in the history
  • Loading branch information
haotianw465 committed Mar 1, 2018
1 parent b9dbaf1 commit c374fd8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 22 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
CHANGELOG
=========

Unreleased
==========
0.96
====
* feature: Add support for SQLAlchemy and Flask-SQLAlcemy. `PR14 <https://github.com/aws/aws-xray-sdk-python/pull/14>`_.
* feature: Add support for PynamoDB calls to DynamoDB. `PR13 <https://github.com/aws/aws-xray-sdk-python/pull/13>`_.
* feature: Add support for httplib calls `PR19 <https://github.com/aws/aws-xray-sdk-python/pull/19>`_.
* feature: Add support for httplib calls. `PR19 <https://github.com/aws/aws-xray-sdk-python/pull/19>`_.
* feature: Make streaming threshold configurable through public interface. `ISSUE21 <https://github.com/aws/aws-xray-sdk-python/issues/21>`_.
* bugfix: Drop invalid annotation keys and log a warning. `PR22 <https://github.com/aws/aws-xray-sdk-python/pull/22>`_.
* bugfix: Respect `with` statement on cursor objects in dbapi2 patcher. `PR17 <https://github.com/aws/aws-xray-sdk-python/pull/17>`_.
* bugfix: Don't throw error from built in subsegment capture when `LOG_ERROR` is set. `ISSUE4 <https://github.com/aws/aws-xray-sdk-python/issues/4>`_.

0.95
====
Expand Down
21 changes: 19 additions & 2 deletions aws_xray_sdk/core/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def configure(self, sampling=None, plugins=None,
context_missing=None, sampling_rules=None,
daemon_address=None, service=None,
context=None, emitter=None,
dynamic_naming=None):
dynamic_naming=None, streaming_threshold=None):
"""Configure global X-Ray recorder.
Configure needs to run before patching thrid party libraries
Expand Down Expand Up @@ -90,6 +90,9 @@ def configure(self, sampling=None, plugins=None,
:param dynamic_naming: a string that defines a pattern that host names
should match. Alternatively you can pass a module which
overrides ``DefaultDynamicNaming`` module.
:param streaming_threshold: If breaks within a single segment it will
start streaming out children subsegments. By default it is the
maximum number of subsegments within a segment.
Environment variables AWS_XRAY_DAEMON_ADDRESS, AWS_XRAY_CONTEXT_MISSING
and AWS_XRAY_TRACING_NAME respectively overrides arguments
Expand All @@ -111,6 +114,8 @@ def configure(self, sampling=None, plugins=None,
self.context.context_missing = os.getenv(CONTEXT_MISSING_KEY, context_missing)
if dynamic_naming:
self.dynamic_naming = dynamic_naming
if streaming_threshold:
self.streaming_threshold = streaming_threshold

plugin_modules = None
if plugins:
Expand Down Expand Up @@ -259,7 +264,7 @@ def stream_subsegments(self):
if not segment or not segment.sampled:
return

if segment.get_total_subsegments_size() <= self._max_subsegments:
if segment.get_total_subsegments_size() <= self.streaming_threshold:
return

# find all subsegments that has no open child subsegments and
Expand Down Expand Up @@ -326,6 +331,10 @@ def record_subsegment(self, wrapped, instance, args, kwargs, name,
stack = traceback.extract_stack(limit=self._max_trace_back)
raise
finally:
# No-op if subsegment is `None` due to `LOG_ERROR`.
if subsegment is None:
return

This comment has been minimized.

Copy link
@nelz9999

nelz9999 Mar 18, 2018

Contributor

Aren't you losing return_value here?


end_time = time.time()
if callable(meta_processor):
meta_processor(
Expand Down Expand Up @@ -440,3 +449,11 @@ def emitter(self):
@emitter.setter
def emitter(self, value):
self._emitter = value

@property
def streaming_threshold(self):
return self._max_subsegments

@streaming_threshold.setter
def streaming_threshold(self, value):
self._max_subsegments = value
1 change: 1 addition & 0 deletions aws_xray_sdk/ext/django/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def ready(self):
plugins=settings.PLUGINS,
service=settings.AWS_XRAY_TRACING_NAME,
dynamic_naming=settings.DYNAMIC_NAMING,
streaming_threshold=settings.STREAMING_THRESHOLD,
)

# if turned on subsegment will be generated on
Expand Down
1 change: 1 addition & 0 deletions aws_xray_sdk/ext/django/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'SAMPLING_RULES': None,
'AWS_XRAY_TRACING_NAME': None,
'DYNAMIC_NAMING': None,
'STREAMING_THRESHOLD': None,
}

XRAY_NAMESPACE = 'XRAY_RECORDER'
Expand Down
24 changes: 12 additions & 12 deletions aws_xray_sdk/ext/httplib/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

_XRAY_PROP = '_xray_prop'
_XRay_Data = namedtuple('xray_data', ['method', 'host', 'url'])
# A flag indicates whether this module is X-Ray patched or not
PATCH_FLAG = '__xray_patched'


def http_response_processor(wrapped, instance, args, kwargs, return_value,
Expand Down Expand Up @@ -113,11 +115,10 @@ def _xray_traced_http_client_read(wrapped, instance, args, kwargs):

def patch():
""" patch the built-in urllib/httplib/httplib.client methods for tracing"""

# we set an attribute to avoid double unwrapping
if getattr(httplib, '__xray_patch', False):
if getattr(httplib, PATCH_FLAG, False):
return
setattr(httplib, '__xray_patch', True)
# we set an attribute to avoid multiple wrapping
setattr(httplib, PATCH_FLAG, True)

wrapt.wrap_function_wrapper(
httplib_client_module,
Expand All @@ -139,13 +140,12 @@ def patch():


def unpatch():
""" unpatch any previously patched modules """
if not getattr(httplib, '__xray_patch', False):
return
setattr(httplib, '__xray_patch', False)

# send_request encapsulates putrequest, putheader[s], and endheaders
# NOTE that requests
"""
Unpatch any previously patched modules.
This operation is idempotent.
"""
setattr(httplib, PATCH_FLAG, False)
# _send_request encapsulates putrequest, putheader[s], and endheaders
unwrap(httplib.HTTPConnection, '_send_request')
unwrap(httplib.HTTPConnection, 'getresponse')
unwrap(httplib.HTTPConnection, 'read')
unwrap(httplib.HTTPResponse, 'read')
1 change: 1 addition & 0 deletions docs/frameworks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The default values are as follows::
'SAMPLING_RULES': None,
'AWS_XRAY_TRACING_NAME': None, # the segment name for segments generated from incoming requests
'DYNAMIC_NAMING': None, # defines a pattern that host names should match
'STREAMING_THRESHOLD': None, # defines when a segment starts to stream out its children subsegments
}

Environment variables have higher precedence over user settings.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='aws-xray-sdk',
version='0.95',
version='0.96',

description='The AWS X-Ray SDK for Python (the SDK) enables Python developers to record'
' and emit information from within their applications to the AWS X-Ray service.',
Expand Down
22 changes: 22 additions & 0 deletions tests/ext/botocore/test_botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ def test_map_parameter_grouping():

aws_meta = subsegment.aws
assert sorted(aws_meta['table_names']) == ['table1', 'table2']

def test_pass_through_on_context_missing():
"""
The built-in patcher or subsegment capture logic should not throw
any error when a `None` subsegment created from `LOG_ERROR` missing context.
"""
xray_recorder.configure(context_missing='LOG_ERROR')
xray_recorder.clear_trace_entities()

ddb = session.create_client('dynamodb', region_name='us-west-2')
response = {
'ResponseMetadata': {
'RequestId': REQUEST_ID,
'HTTPStatusCode': 200,
}
}

with Stubber(ddb) as stubber:
stubber.add_response('describe_table', response, {'TableName': 'mytable'})
ddb.describe_table(TableName='mytable')

xray_recorder.configure(context_missing='RUNTIME_ERROR')
9 changes: 5 additions & 4 deletions tests/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ def test_subsegment_parenting():


def test_subsegments_streaming():

xray_recorder.configure(streaming_threshold=10)
segment = xray_recorder.begin_segment('name')
for i in range(0, 50):
for i in range(0, 11):
xray_recorder.begin_subsegment(name=str(i))
for i in range(0, 40):
for i in range(0, 1):
# subsegment '10' will be streamed out upon close
xray_recorder.end_subsegment()

assert segment.get_total_subsegments_size() < 50
assert segment.get_total_subsegments_size() == 10
assert xray_recorder.current_subsegment().name == '9'

0 comments on commit c374fd8

Please sign in to comment.