Skip to content

Commit bf4bcdd

Browse files
authored
Merge branch 'master' into setup
2 parents d98ce83 + 7fba3a3 commit bf4bcdd

29 files changed

+346
-76
lines changed

.github/workflows/IntegrationTesting.yaml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ jobs:
1111

1212
steps:
1313
- name: Pull in source code from aws-xray-sdk-python Github repository
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v3
1515

1616
- name: Setup python
17-
uses: actions/setup-python@v2
17+
uses: actions/setup-python@v4
1818
with:
1919
python-version: '3.8'
2020

2121
- name: Build X-Ray Python SDK
2222
run: python setup.py sdist
2323

2424
- name: Upload SDK build artifact
25-
uses: actions/upload-artifact@v2
25+
uses: actions/upload-artifact@v3
2626
with:
2727
name: sdk-build-artifact
2828
path: .
@@ -33,15 +33,15 @@ jobs:
3333
runs-on: ubuntu-latest
3434

3535
steps:
36-
- uses: actions/checkout@v2
36+
- uses: actions/checkout@v3
3737

3838
- name: Setup python
39-
uses: actions/setup-python@v2
39+
uses: actions/setup-python@v4
4040
with:
4141
python-version: '3.8'
4242

4343
- name: Download X-Ray SDK build artifact
44-
uses: actions/download-artifact@v2
44+
uses: actions/download-artifact@v3
4545
with:
4646
name: sdk-build-artifact
4747
path: ./sample-apps/flask
@@ -55,7 +55,7 @@ jobs:
5555
working-directory: ./sample-apps/flask
5656

5757
- name: Upload WebApp with X-Ray SDK build artifact
58-
uses: actions/upload-artifact@v2
58+
uses: actions/upload-artifact@v3
5959
with:
6060
name: sdk-flask-build-artifact
6161
path: ./sample-apps/flask/deploy.zip
@@ -67,10 +67,10 @@ jobs:
6767

6868
steps:
6969
- name: Checkout X-Ray SDK to get terraform source
70-
uses: actions/checkout@v2
70+
uses: actions/checkout@v3
7171

7272
- name: Download WebApp with X-Ray SDK build artifact
73-
uses: actions/download-artifact@v2
73+
uses: actions/download-artifact@v3
7474
with:
7575
name: sdk-flask-build-artifact
7676

@@ -85,7 +85,7 @@ jobs:
8585
aws-region: us-west-2
8686

8787
- name: Setup Terraform
88-
uses: hashicorp/setup-terraform@v1
88+
uses: hashicorp/setup-terraform@v2
8989

9090
- name: Terraform Init
9191
run: terraform init
@@ -109,7 +109,7 @@ jobs:
109109
working-directory: ./terraform
110110

111111
- name: Upload terraform state files for destorying resources
112-
uses: actions/upload-artifact@v2
112+
uses: actions/upload-artifact@v3
113113
with:
114114
name: terraform-state-artifact
115115
path: ./terraform
@@ -120,8 +120,9 @@ jobs:
120120
runs-on: ubuntu-latest
121121

122122
steps:
123-
- uses: actions/setup-java@v1
123+
- uses: actions/setup-java@v3
124124
with:
125+
distribution: 'zulu'
125126
java-version: 14
126127

127128
- name: Configure AWS Credentials
@@ -132,7 +133,7 @@ jobs:
132133
aws-region: us-west-2
133134

134135
- name: Checkout test framework
135-
uses: actions/checkout@v2
136+
uses: actions/checkout@v3
136137
with:
137138
repository: aws-observability/aws-otel-test-framework
138139
ref: terraform
@@ -148,7 +149,7 @@ jobs:
148149

149150
steps:
150151
- name: Download terraform state artifact
151-
uses: actions/download-artifact@v2
152+
uses: actions/download-artifact@v3
152153
with:
153154
name: terraform-state-artifact
154155

@@ -160,7 +161,7 @@ jobs:
160161
aws-region: us-west-2
161162

162163
- name: Setup Terraform
163-
uses: hashicorp/setup-terraform@v1
164+
uses: hashicorp/setup-terraform@v2
164165

165166
- name: Terraform Init
166167
run: terraform init

.github/workflows/Release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout master branch
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616

1717
- name: Create Release
1818
id: create_release

.github/workflows/UnitTesting.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ jobs:
2828
testenv: [core, ext]
2929
steps:
3030
- name: Checkout repo
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3232

3333
- name: Setup Python
34-
uses: actions/setup-python@v2
34+
uses: actions/setup-python@v4
3535
with:
3636
python-version: ${{ env[matrix.python-version] }}
3737

3838
- name: Install tox
39-
run: pip install -U tox-factor
39+
run: pip install "tox<=3.27.1" -U tox-factor
4040

4141
- name: Cache tox environment
4242
# Preserves .tox directory between runs for faster installs
43-
uses: actions/cache@v2
43+
uses: actions/cache@v3
4444
with:
4545
path: |
4646
.tox

.github/workflows/continuous-monitoring.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout Repository
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v3
1414

1515
- name: Configure AWS Credentials
1616
uses: aws-actions/configure-aws-credentials@v1
@@ -19,7 +19,7 @@ jobs:
1919
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2020
aws-region: us-east-1
2121

22-
- uses: actions/setup-python@v2
22+
- uses: actions/setup-python@v4
2323
with:
2424
python-version: '3.x'
2525

CHANGELOG.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ CHANGELOG
55
Unreleased
66
==========
77

8+
2.11.0
9+
==========
10+
* bugfix: Fix TypeError by patching register_default_jsonb from psycopg2 `PR350 https://github.com/aws/aws-xray-sdk-python/pull/350`
11+
* improvement: Add annotations `PR348 https://github.com/aws/aws-xray-sdk-python/pull/348`
12+
* bugfix: Use service parameter to match centralized sampling rules `PR 353 https://github.com/aws/aws-xray-sdk-python/pull/353`
13+
* bugfix: Implement PEP3134 to discover underlying problems with python3 `PR355 https://github.com/aws/aws-xray-sdk-python/pull/355`
14+
* improvement: Allow list TopicArn for SNS PublishBatch request `PR358 https://github.com/aws/aws-xray-sdk-python/pull/358`
15+
* bugfix: Version pinning flask-sqlalchemy version to 2.5.1 or less `PR360 https://github.com/aws/aws-xray-sdk-python/pull/360`
16+
* bugfix: Fix UnboundLocalError when aiohttp server raises a CancelledError `PR356 https://github.com/aws/aws-xray-sdk-python/pull/356`
17+
* improvement: Instrument httpx >= 0.20 `PR357 https://github.com/aws/aws-xray-sdk-python/pull/357`
18+
* improvement: [LambdaContext] persist original trace header `PR362 https://github.com/aws/aws-xray-sdk-python/pull/362`
19+
* bugfix: Run tests against Django 4.x `PR361 https://github.com/aws/aws-xray-sdk-python/pull/361`
20+
* improvement: Oversampling Mitigation `PR366 https://github.com/aws/aws-xray-sdk-python/pull/366`
21+
822
2.10.0
923
==========
1024
* bugfix: Only import future for py2. `PR343 <https://github.com/aws/aws-xray-sdk-python/pull/343>`_.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ xray_recorder.end_subsegment()
124124
xray_recorder.end_segment()
125125
```
126126

127+
### Oversampling Mitigation
128+
To modify the sampling decision at the subsegment level, subsegments that inherit the decision of their direct parent (segment or subsegment) can be created using `xray_recorder.begin_subsegment()` and unsampled subsegments can be created using
129+
`xray_recorder.begin_subsegment_without_sampling()`.
130+
131+
The code snippet below demonstrates creating a sampled or unsampled subsegment based on the sampling decision of each SQS message processed by Lambda.
132+
133+
```python
134+
from aws_xray_sdk.core import xray_recorder
135+
from aws_xray_sdk.core.models.subsegment import Subsegment
136+
from aws_xray_sdk.core.utils.sqs_message_helper import SqsMessageHelper
137+
138+
def lambda_handler(event, context):
139+
140+
for message in event['Records']:
141+
if SqsMessageHelper.isSampled(message):
142+
subsegment = xray_recorder.begin_subsegment('sampled_subsegment')
143+
print('sampled - processing SQS message')
144+
145+
else:
146+
subsegment = xray_recorder.begin_subsegment_without_sampling('unsampled_subsegment')
147+
print('unsampled - processing SQS message')
148+
149+
xray_recorder.end_subsegment()
150+
```
151+
152+
The code snippet below demonstrates wrapping a downstream AWS SDK request with an unsampled subsegment.
153+
```python
154+
from aws_xray_sdk.core import xray_recorder, patch_all
155+
import boto3
156+
157+
patch_all()
158+
159+
def lambda_handler(event, context):
160+
subsegment = xray_recorder.begin_subsegment_without_sampling('unsampled_subsegment')
161+
client = boto3.client('sqs')
162+
print(client.list_queues())
163+
164+
xray_recorder.end_subsegment()
165+
```
166+
127167
### Capture
128168

129169
As a decorator:

aws_xray_sdk/core/async_recorder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
import six
32

43
from aws_xray_sdk.core.recorder import AWSXRayRecorder
54
from aws_xray_sdk.core.utils import stacktrace
@@ -82,10 +81,10 @@ async def record_subsegment_async(self, wrapped, instance, args, kwargs, name,
8281
try:
8382
return_value = await wrapped(*args, **kwargs)
8483
return return_value
85-
except Exception as exc:
86-
exception = exc
84+
except Exception as e:
85+
exception = e
8786
stack = stacktrace.get_stacktrace(limit=self._max_trace_back)
88-
six.raise_from(exc, exc)
87+
raise
8988
finally:
9089
# No-op if subsegment is `None` due to `LOG_ERROR`.
9190
if subsegment is not None:

aws_xray_sdk/core/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Context(object):
2727
2828
This data structure is thread-safe.
2929
"""
30-
def __init__(self, context_missing='RUNTIME_ERROR'):
30+
def __init__(self, context_missing='LOG_ERROR'):
3131

3232
self._local = threading.local()
3333
strategy = os.getenv(CXT_MISSING_STRATEGY_KEY, context_missing)

aws_xray_sdk/core/models/dummy_entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DummySegment(Segment):
1111
the segment based on sampling rules.
1212
Adding data to a dummy segment becomes a no-op except for
1313
subsegments. This is to reduce the memory footprint of the SDK.
14-
A dummy segment will not be sent to the X-Ray daemon. Manually create
14+
A dummy segment will not be sent to the X-Ray daemon. Manually creating
1515
dummy segments is not recommended.
1616
"""
1717

aws_xray_sdk/core/models/entity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def add_subsegment(self, subsegment):
8181
"""
8282
self._check_ended()
8383
subsegment.parent_id = self.id
84+
85+
if not self.sampled and subsegment.sampled:
86+
log.warning("This sampled subsegment is being added to an unsampled parent segment/subsegment and will be orphaned.")
87+
8488
self.subsegments.append(subsegment)
8589

8690
def remove_subsegment(self, subsegment):

aws_xray_sdk/core/patcher.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77
import sys
88
import wrapt
9-
import six
109

1110
from aws_xray_sdk import global_sdk_config
1211
from .utils.compat import PY2, is_classmethod, is_instance_method
@@ -110,9 +109,9 @@ def patch(modules_to_patch, raise_errors=True, ignore_module_patterns=None):
110109
def _patch_module(module_to_patch, raise_errors=True):
111110
try:
112111
_patch(module_to_patch)
113-
except Exception as exc:
112+
except Exception:
114113
if raise_errors:
115-
six.raise_from(exc, exc)
114+
raise
116115
log.debug('failed to patch module %s', module_to_patch)
117116

118117

0 commit comments

Comments
 (0)