Skip to content

Commit

Permalink
Merge branch 'master' into doc_update
Browse files Browse the repository at this point in the history
  • Loading branch information
srprash committed Sep 25, 2023
2 parents 4bea199 + 2976b25 commit 07b56e9
Show file tree
Hide file tree
Showing 66 changed files with 247 additions and 382 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/UnitTesting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@ on:

jobs:
test:
# "setup-python" action doesn't provide python 3.4 binaries for ubuntu-latest.
# Sticking to Ubuntu 18.04 as recommended here:
# https://github.com/actions/setup-python/issues/185#issuecomment-768232756
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
env:
py27: 2.7
py34: 3.4
py35: 3.5
py36: 3.6
py37: 3.7
py38: 3.8
py39: 3.9
py310: '3.10'
py311: '3.11'
DB_DATABASE: test_db
DB_USER: root
DB_PASSWORD: root
strategy:
fail-fast: false
matrix:
python-version: [py27, py34, py35, py36, py37, py38, py39]
python-version: [py37, py38, py39, py310, py311]
testenv: [core, ext]
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Start MySQL
if: ${{ matrix.testenv == 'ext' }}
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
- name: Setup Python
uses: actions/setup-python@v4
with:
Expand Down
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ CHANGELOG
Unreleased
==========

2.12.0
==========
* improvement: Default Context Missing Strategy set to Log Error `PR372 https://github.com/aws/aws-xray-sdk-python/pull/372`
* bugfix: Pin tox version to <=3.27.1 to fix CI tests `PR374 https://github.com/aws/aws-xray-sdk-python/pull/374`
* improvement: Sample app dependency update `PR373 https://github.com/aws/aws-xray-sdk-python/pull/373`
* bugfix: Fix pynamodb tests for Python < 3.6 `PR375 https://github.com/aws/aws-xray-sdk-python/pull/375`
* improvement: Use latest GH Actions versions in CI tests `PR365 https://github.com/aws/aws-xray-sdk-python/pull/365`
* improvement: Simplify setup script `PR363 https://github.com/aws/aws-xray-sdk-python/pull/363`
* bugfix: Fix deprecation warnings related to asyncio `PR364 https://github.com/aws/aws-xray-sdk-python/pull/364`
* improvement: Run tests against Python 3.10 and 3.11 `PR376 https://github.com/aws/aws-xray-sdk-python/pull/376`
* improvement: Sample app dependency update `PR380 https://github.com/aws/aws-xray-sdk-python/pull/380`
* bugfix: Pin sqlalchemy version to 1.x to fix tests `PR381 https://github.com/aws/aws-xray-sdk-python/pull/381`
* bugfix: Fix sample app dependencies incompatibility with XRay SDK `PR382 https://github.com/aws/aws-xray-sdk-python/pull/382`
* bugfix: Start MySQL from GH Actions, upgrade Ubuntu, and remove Python versions for unit tests `PR384 https://github.com/aws/aws-xray-sdk-python/pull/384`

2.11.0
==========
* bugfix: Fix TypeError by patching register_default_jsonb from psycopg2 `PR350 https://github.com/aws/aws-xray-sdk-python/pull/350`
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ AWS X-Ray supports using OpenTelemetry Python and the AWS Distro for OpenTelemet

If you want additional features when tracing your Python applications, please [open an issue on the OpenTelemetry Python Instrumentation repository](https://github.com/open-telemetry/opentelemetry-python-contrib/issues/new?labels=feature-request&template=feature_request.md&title=X-Ray%20Compatible%20Feature%20Request).

### :mega: Python Versions End-of-Support Notice

AWS X-Ray SDK for Python versions `>2.11.0` has dropped support for Python 2.7, 3.4, 3.5, and 3.6.

# AWS X-Ray SDK for Python

![Screenshot of the AWS X-Ray console](/images/example_servicemap.png?raw=true)

## Installing

The AWS X-Ray SDK for Python is compatible with Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, and 3.9.
The AWS X-Ray SDK for Python is compatible with Python 3.7, 3.8, 3.9, 3.10, and 3.11.

Install the SDK using the following command (the SDK's non-testing dependencies will be installed).

Expand Down
11 changes: 3 additions & 8 deletions aws_xray_sdk/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from .async_recorder import AsyncAWSXRayRecorder
from .patcher import patch, patch_all
from .recorder import AWSXRayRecorder
from .patcher import patch_all, patch
from .utils.compat import PY35


if not PY35:
xray_recorder = AWSXRayRecorder()
else:
from .async_recorder import AsyncAWSXRayRecorder
xray_recorder = AsyncAWSXRayRecorder()
xray_recorder = AsyncAWSXRayRecorder()

__all__ = [
'patch',
Expand Down
27 changes: 6 additions & 21 deletions aws_xray_sdk/core/async_context.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import asyncio
import sys
import copy

from .context import Context as _Context

_GTE_PY37 = sys.version_info.major == 3 and sys.version_info.minor >= 7


class AsyncContext(_Context):
"""
Expand All @@ -16,7 +13,7 @@ class AsyncContext(_Context):
Also overrides clear_trace_entities
"""
def __init__(self, *args, loop=None, use_task_factory=True, **kwargs):
super(AsyncContext, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self._loop = loop
if loop is None:
Expand All @@ -35,7 +32,7 @@ def clear_trace_entities(self):
self._local.clear()


class TaskLocalStorage(object):
class TaskLocalStorage:
"""
Simple task local storage
"""
Expand All @@ -51,10 +48,7 @@ def __setattr__(self, name, value):

else:
# Set task local attributes
if _GTE_PY37:
task = asyncio.current_task(loop=self._loop)
else:
task = asyncio.Task.current_task(loop=self._loop)
task = asyncio.current_task(loop=self._loop)
if task is None:
return None

Expand All @@ -68,10 +62,7 @@ def __getattribute__(self, item):
# Return references to local objects
return object.__getattribute__(self, item)

if _GTE_PY37:
task = asyncio.current_task(loop=self._loop)
else:
task = asyncio.Task.current_task(loop=self._loop)
task = asyncio.current_task(loop=self._loop)
if task is None:
return None

Expand All @@ -82,10 +73,7 @@ def __getattribute__(self, item):

def clear(self):
# If were in a task, clear the context dictionary
if _GTE_PY37:
task = asyncio.current_task(loop=self._loop)
else:
task = asyncio.Task.current_task(loop=self._loop)
task = asyncio.current_task(loop=self._loop)
if task is not None and hasattr(task, 'context'):
task.context.clear()

Expand All @@ -104,10 +92,7 @@ def task_factory(loop, coro):
del task._source_traceback[-1] # flake8: noqa

# Share context with new task if possible
if _GTE_PY37:
current_task = asyncio.current_task(loop=loop)
else:
current_task = asyncio.Task.current_task(loop=loop)
current_task = asyncio.current_task(loop=loop)
if current_task is not None and hasattr(current_task, 'context'):
if current_task.context.get('entities'):
# NOTE: (enowell) Because the `AWSXRayRecorder`'s `Context` decides
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CXT_MISSING_STRATEGY_KEY = 'AWS_XRAY_CONTEXT_MISSING'


class Context(object):
class Context:
"""
The context storage class to store trace entities(segments/subsegments).
The default implementation uses threadlocal to store these entities.
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/daemon_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DEFAULT_ADDRESS = '127.0.0.1:2000'


class DaemonConfig(object):
class DaemonConfig:
"""The class that stores X-Ray daemon configuration about
the ip address and port for UDP and TCP port. It gets the address
string from ``AWS_TRACING_DAEMON_ADDRESS`` and then from recorder's
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/emitters/udp_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DEFAULT_DAEMON_ADDRESS = '127.0.0.1:2000'


class UDPEmitter(object):
class UDPEmitter:
"""
The default emitter the X-Ray recorder uses to send segments/subsegments
to the X-Ray daemon over UDP using a non-blocking socket. If there is an
Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/default_dynamic_naming.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..utils.search_pattern import wildcard_match


class DefaultDynamicNaming(object):
class DefaultDynamicNaming:
"""
Decides what name to use on a segment generated from an incoming request.
By default it takes the host name and compares it to a pre-defined pattern.
Expand Down
6 changes: 3 additions & 3 deletions aws_xray_sdk/core/models/dummy_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class DummySegment(Segment):
def __init__(self, name='dummy'):
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
if no_op_id and no_op_id.lower() == 'false':
super(DummySegment, self).__init__(name=name, traceid=TraceId().to_id())
super().__init__(name=name, traceid=TraceId().to_id())
else:
super(DummySegment, self).__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
super().__init__(name=name, traceid=NoOpTraceId().to_id(), entityid='0000000000000000')
self.sampled = False

def set_aws(self, aws_meta):
Expand Down Expand Up @@ -87,7 +87,7 @@ class DummySubsegment(Subsegment):
"""

def __init__(self, segment, name='dummy'):
super(DummySubsegment, self).__init__(name, 'dummy', segment)
super().__init__(name, 'dummy', segment)
no_op_id = os.getenv('AWS_XRAY_NOOP_ID')
if no_op_id and no_op_id.lower() == 'false':
super(Subsegment, self).__init__(name)
Expand Down
12 changes: 6 additions & 6 deletions aws_xray_sdk/core/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import json

from ..utils.compat import annotation_value_types, string_types
from ..utils.compat import annotation_value_types
from ..utils.conversion import metadata_to_dict
from .throwable import Throwable
from . import http
Expand All @@ -21,7 +21,7 @@
ORIGIN_TRACE_HEADER_ATTR_KEY = '_origin_trace_header'


class Entity(object):
class Entity:
"""
The parent class for segment/subsegment. It holds common properties
and methods on segment and subsegment.
Expand Down Expand Up @@ -113,7 +113,7 @@ def put_http_meta(self, key, value):
return

if key == http.STATUS:
if isinstance(value, string_types):
if isinstance(value, str):
value = int(value)
self.apply_status_code(value)

Expand All @@ -139,7 +139,7 @@ def put_annotation(self, key, value):
"""
self._check_ended()

if not isinstance(key, string_types):
if not isinstance(key, str):
log.warning("ignoring non string type annotation key with type %s.", type(key))
return

Expand All @@ -165,7 +165,7 @@ def put_metadata(self, key, value, namespace='default'):
"""
self._check_ended()

if not isinstance(namespace, string_types):
if not isinstance(namespace, str):
log.warning("ignoring non string type metadata namespace")
return

Expand Down Expand Up @@ -271,7 +271,7 @@ def serialize(self):
def to_dict(self):
"""
Convert Entity(Segment/Subsegment) object to dict
with required properties that have non-empty values.
with required properties that have non-empty values.
"""
entity_dict = {}

Expand Down
2 changes: 1 addition & 1 deletion aws_xray_sdk/core/models/facade_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, name, entityid, traceid, sampled):
sampled=sampled,
)

super(FacadeSegment, self).__init__(
super().__init__(
name=name,
entityid=entityid,
traceid=traceid,
Expand Down
10 changes: 5 additions & 5 deletions aws_xray_sdk/core/models/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, name, entityid=None, traceid=None,
if not name:
raise SegmentNameMissingException("Segment name is required.")

super(Segment, self).__init__(name)
super().__init__(name)

if not traceid:
traceid = TraceId().to_id()
Expand All @@ -85,7 +85,7 @@ def add_subsegment(self, subsegment):
Add input subsegment as a child subsegment and increment
reference counter and total subsegments counter.
"""
super(Segment, self).add_subsegment(subsegment)
super().add_subsegment(subsegment)
self.increment()

def increment(self):
Expand Down Expand Up @@ -127,15 +127,15 @@ def remove_subsegment(self, subsegment):
"""
Remove the reference of input subsegment.
"""
super(Segment, self).remove_subsegment(subsegment)
super().remove_subsegment(subsegment)
self.decrement_subsegments_size()

def set_user(self, user):
"""
set user of a segment. One segment can only have one user.
User is indexed and can be later queried.
"""
super(Segment, self)._check_ended()
super()._check_ended()
self.user = user

def set_service(self, service_info):
Expand All @@ -160,7 +160,7 @@ def to_dict(self):
Convert Segment object to dict with required properties
that have non-empty values.
"""
segment_dict = super(Segment, self).to_dict()
segment_dict = super().to_dict()

del segment_dict['ref_counter']
del segment_dict['_subsegments_counter']
Expand Down
Loading

0 comments on commit 07b56e9

Please sign in to comment.