Skip to content

Commit 8268053

Browse files
committed
2.2.0 release commit
1 parent 41b776d commit 8268053

File tree

10 files changed

+42
-9
lines changed

10 files changed

+42
-9
lines changed

CHANGELOG.rst

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
CHANGELOG
33
=========
44

5+
2.2.0
6+
=====
7+
* feature: Added context managers on segment/subsegment capture. `PR97 <https://github.com/aws/aws-xray-sdk-python/pull/97>`_.
8+
* feature: Added AWS SNS topic ARN to the default whitelist file. `PR93 <https://github.com/aws/aws-xray-sdk-python/pull/93>`_.
9+
* bugfix: Fixed an issue on `psycopg2` to support all keywords. `PR91 <https://github.com/aws/aws-xray-sdk-python/pull/91>`_.
10+
* bugfix: Fixed an issue on `endSegment` when there is context missing. `ISSUE98 <https://github.com/aws/aws-xray-sdk-python/issues/98>`_.
11+
* bugfix: Fixed the package description rendered on PyPI. `PR101 <https://github.com/aws/aws-xray-sdk-python/pull/101>`_.
12+
* 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>`_.
13+
* bugfix: Fixed the `datetime` to `epoch` conversion on Windows OS. `ISSUE103 <https://github.com/aws/aws-xray-sdk-python/issues/103>`_.
14+
* bugfix: Fixed a wrong segment json key where it should be `sampling_rule_name` rather than `rule_name`.
15+
516
2.1.0
617
=====
718
* feature: Added support for `psycopg2`. `PR83 <https://github.com/aws/aws-xray-sdk-python/pull/83>`_.

aws_xray_sdk/core/models/segment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def set_rule_name(self, rule_name):
153153
"""
154154
if not self.aws.get('xray', None):
155155
self.aws['xray'] = {}
156-
self.aws['xray']['rule_name'] = rule_name
156+
self.aws['xray']['sampling_rule_name'] = rule_name
157157

158158
def save_origin_trace_header(self, trace_header):
159159
"""

aws_xray_sdk/core/patcher.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _patch(module_to_patch):
7373

7474
if module_to_patch in _PATCHED_MODULES:
7575
log.debug('%s already patched', module_to_patch)
76+
return
7677

7778
imported_module = importlib.import_module(path)
7879
imported_module.patch()

aws_xray_sdk/core/recorder.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ def end_segment(self, end_time=None):
242242
:param float end_time: segment compeletion in unix epoch in seconds.
243243
"""
244244
self.context.end_segment(end_time)
245-
if self.current_segment().ready_to_send():
245+
segment = self.current_segment()
246+
if segment and segment.ready_to_send():
246247
self._send_segment()
247248

248249
def current_segment(self):

aws_xray_sdk/core/sampling/connector.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import binascii
22
import os
33
import time
4+
from datetime import datetime
45

56
import botocore.session
67
from botocore import UNSIGNED
@@ -9,6 +10,7 @@
910
from .sampling_rule import SamplingRule
1011
from aws_xray_sdk.core.models.dummy_entities import DummySegment
1112
from aws_xray_sdk.core.context import Context
13+
from aws_xray_sdk.core.utils.compat import PY2
1214

1315

1416
class ServiceConnector(object):
@@ -86,7 +88,7 @@ def fetch_sampling_target(self, rules):
8688

8789
targets_mapping = {}
8890
for doc in new_docs:
89-
TTL = int(doc['ReservoirQuotaTTL'].strftime('%s')) if doc.get('ReservoirQuotaTTL', None) else None
91+
TTL = self._dt_to_epoch(doc['ReservoirQuotaTTL']) if doc.get('ReservoirQuotaTTL', None) else None
9092
target = {
9193
'rate': doc['FixedRate'],
9294
'quota': doc.get('ReservoirQuota', None),
@@ -95,7 +97,7 @@ def fetch_sampling_target(self, rules):
9597
}
9698
targets_mapping[doc['RuleName']] = target
9799

98-
return targets_mapping, int(resp['LastRuleModification'].strftime('%s'))
100+
return targets_mapping, self._dt_to_epoch(resp['LastRuleModification'])
99101

100102
def setup_xray_client(self, ip, port, client):
101103
"""
@@ -131,6 +133,21 @@ def _generate_reporting_docs(self, rules, now):
131133
report_docs.append(doc)
132134
return report_docs
133135

136+
def _dt_to_epoch(self, dt):
137+
"""
138+
Convert a offset-aware datetime to POSIX time.
139+
"""
140+
if PY2:
141+
# The input datetime is from botocore unmarshalling and it is
142+
# offset-aware so the timedelta of subtracting this time
143+
# to 01/01/1970 using the same tzinfo gives us
144+
# Unix Time (also known as POSIX Time).
145+
time_delta = dt - datetime(1970, 1, 1).replace(tzinfo=dt.tzinfo)
146+
return int(time_delta.total_seconds())
147+
else:
148+
# Added in python 3.3+ and directly returns POSIX time.
149+
return int(dt.timestamp())
150+
134151
def _is_rule_valid(self, record):
135152
# We currently only handle v1 sampling rules.
136153
return record.get('Version', None) == 1 and \

aws_xray_sdk/ext/httplib/patch.py

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from aws_xray_sdk.core import xray_recorder
66
from aws_xray_sdk.core.models import http
77
from aws_xray_sdk.core.exceptions.exceptions import SegmentNotFoundException
8+
from aws_xray_sdk.core.patcher import _PATCHED_MODULES
89
from aws_xray_sdk.ext.util import inject_trace_header, strip_url, unwrap
910

1011
if sys.version_info >= (3, 0, 0):
@@ -169,6 +170,7 @@ def unpatch():
169170
Unpatch any previously patched modules.
170171
This operation is idempotent.
171172
"""
173+
_PATCHED_MODULES.discard('httplib')
172174
setattr(httplib, PATCH_FLAG, False)
173175
# _send_request encapsulates putrequest, putheader[s], and endheaders
174176
unwrap(httplib.HTTPConnection, '_send_request')

aws_xray_sdk/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.1.0'
1+
VERSION = '2.2.0'

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
# built documents.
6363
#
6464
# The short X.Y version.
65-
version = u'2.1.0'
65+
version = u'2.2.0'
6666
# The full version, including alpha/beta/rc tags.
67-
release = u'2.1.0'
67+
release = u'2.2.0'
6868

6969
# The language for content autogenerated by Sphinx. Refer to documentation
7070
# for a list of supported languages.

tests/test_recorder.py

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def test_pass_through_with_missing_context():
8787

8888
xray_recorder.put_annotation('key', 'value')
8989
xray_recorder.put_metadata('key', 'value')
90+
xray_recorder.end_segment()
9091

9192

9293
def test_capture_not_suppress_exception():

tests/test_trace_entities.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def test_no_rule_name_pollution():
154154
segment1.set_rule_name('rule1')
155155
segment2.set_rule_name('rule2')
156156

157-
assert segment1.aws['xray']['rule_name'] == 'rule1'
158-
assert segment2.aws['xray']['rule_name'] == 'rule2'
157+
assert segment1.aws['xray']['sampling_rule_name'] == 'rule1'
158+
assert segment2.aws['xray']['sampling_rule_name'] == 'rule2'
159159

160160

161161
def test_no_empty_properties():

0 commit comments

Comments
 (0)