Skip to content

Commit

Permalink
2.2.0 release commit
Browse files Browse the repository at this point in the history
  • Loading branch information
haotianw465 committed Oct 5, 2018
1 parent 41b776d commit 8268053
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
CHANGELOG
=========

2.2.0
=====
* feature: Added context managers on segment/subsegment capture. `PR97 <https://github.com/aws/aws-xray-sdk-python/pull/97>`_.
* feature: Added AWS SNS topic ARN to the default whitelist file. `PR93 <https://github.com/aws/aws-xray-sdk-python/pull/93>`_.
* bugfix: Fixed an issue on `psycopg2` to support all keywords. `PR91 <https://github.com/aws/aws-xray-sdk-python/pull/91>`_.
* bugfix: Fixed an issue on `endSegment` when there is context missing. `ISSUE98 <https://github.com/aws/aws-xray-sdk-python/issues/98>`_.
* bugfix: Fixed the package description rendered on PyPI. `PR101 <https://github.com/aws/aws-xray-sdk-python/pull/101>`_.
* bugfix: Fixed an issue where `patch_all` could patch the same module multiple times. `ISSUE99 <https://github.com/aws/aws-xray-sdk-python/issues/99>`_.
* bugfix: Fixed the `datetime` to `epoch` conversion on Windows OS. `ISSUE103 <https://github.com/aws/aws-xray-sdk-python/issues/103>`_.
* bugfix: Fixed a wrong segment json key where it should be `sampling_rule_name` rather than `rule_name`.

2.1.0
=====
* feature: Added support for `psycopg2`. `PR83 <https://github.com/aws/aws-xray-sdk-python/pull/83>`_.
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def set_rule_name(self, rule_name):
"""
if not self.aws.get('xray', None):
self.aws['xray'] = {}
self.aws['xray']['rule_name'] = rule_name
self.aws['xray']['sampling_rule_name'] = rule_name

def save_origin_trace_header(self, trace_header):
"""
Expand Down
1 change: 1 addition & 0 deletions aws_xray_sdk/core/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def _patch(module_to_patch):

if module_to_patch in _PATCHED_MODULES:
log.debug('%s already patched', module_to_patch)
return

imported_module = importlib.import_module(path)
imported_module.patch()
Expand Down
3 changes: 2 additions & 1 deletion aws_xray_sdk/core/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def end_segment(self, end_time=None):
:param float end_time: segment compeletion in unix epoch in seconds.
"""
self.context.end_segment(end_time)
if self.current_segment().ready_to_send():
segment = self.current_segment()
if segment and segment.ready_to_send():
self._send_segment()

def current_segment(self):
Expand Down
21 changes: 19 additions & 2 deletions aws_xray_sdk/core/sampling/connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import binascii
import os
import time
from datetime import datetime

import botocore.session
from botocore import UNSIGNED
Expand All @@ -9,6 +10,7 @@
from .sampling_rule import SamplingRule
from aws_xray_sdk.core.models.dummy_entities import DummySegment
from aws_xray_sdk.core.context import Context
from aws_xray_sdk.core.utils.compat import PY2


class ServiceConnector(object):
Expand Down Expand Up @@ -86,7 +88,7 @@ def fetch_sampling_target(self, rules):

targets_mapping = {}
for doc in new_docs:
TTL = int(doc['ReservoirQuotaTTL'].strftime('%s')) if doc.get('ReservoirQuotaTTL', None) else None
TTL = self._dt_to_epoch(doc['ReservoirQuotaTTL']) if doc.get('ReservoirQuotaTTL', None) else None
target = {
'rate': doc['FixedRate'],
'quota': doc.get('ReservoirQuota', None),
Expand All @@ -95,7 +97,7 @@ def fetch_sampling_target(self, rules):
}
targets_mapping[doc['RuleName']] = target

return targets_mapping, int(resp['LastRuleModification'].strftime('%s'))
return targets_mapping, self._dt_to_epoch(resp['LastRuleModification'])

def setup_xray_client(self, ip, port, client):
"""
Expand Down Expand Up @@ -131,6 +133,21 @@ def _generate_reporting_docs(self, rules, now):
report_docs.append(doc)
return report_docs

def _dt_to_epoch(self, dt):
"""
Convert a offset-aware datetime to POSIX time.
"""
if PY2:
# The input datetime is from botocore unmarshalling and it is
# offset-aware so the timedelta of subtracting this time
# to 01/01/1970 using the same tzinfo gives us
# Unix Time (also known as POSIX Time).
time_delta = dt - datetime(1970, 1, 1).replace(tzinfo=dt.tzinfo)
return int(time_delta.total_seconds())
else:
# Added in python 3.3+ and directly returns POSIX time.
return int(dt.timestamp())

def _is_rule_valid(self, record):
# We currently only handle v1 sampling rules.
return record.get('Version', None) == 1 and \
Expand Down
2 changes: 2 additions & 0 deletions aws_xray_sdk/ext/httplib/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core.models import http
from aws_xray_sdk.core.exceptions.exceptions import SegmentNotFoundException
from aws_xray_sdk.core.patcher import _PATCHED_MODULES
from aws_xray_sdk.ext.util import inject_trace_header, strip_url, unwrap

if sys.version_info >= (3, 0, 0):
Expand Down Expand Up @@ -169,6 +170,7 @@ def unpatch():
Unpatch any previously patched modules.
This operation is idempotent.
"""
_PATCHED_MODULES.discard('httplib')
setattr(httplib, PATCH_FLAG, False)
# _send_request encapsulates putrequest, putheader[s], and endheaders
unwrap(httplib.HTTPConnection, '_send_request')
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.1.0'
VERSION = '2.2.0'
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
# built documents.
#
# The short X.Y version.
version = u'2.1.0'
version = u'2.2.0'
# The full version, including alpha/beta/rc tags.
release = u'2.1.0'
release = u'2.2.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1 change: 1 addition & 0 deletions tests/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_pass_through_with_missing_context():

xray_recorder.put_annotation('key', 'value')
xray_recorder.put_metadata('key', 'value')
xray_recorder.end_segment()


def test_capture_not_suppress_exception():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_trace_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def test_no_rule_name_pollution():
segment1.set_rule_name('rule1')
segment2.set_rule_name('rule2')

assert segment1.aws['xray']['rule_name'] == 'rule1'
assert segment2.aws['xray']['rule_name'] == 'rule2'
assert segment1.aws['xray']['sampling_rule_name'] == 'rule1'
assert segment2.aws['xray']['sampling_rule_name'] == 'rule2'


def test_no_empty_properties():
Expand Down

0 comments on commit 8268053

Please sign in to comment.