Skip to content

Commit 65c7e19

Browse files
authored
Modified context missing strategy default to log error (#372)
1 parent 680c646 commit 65c7e19

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

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/ext/django/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
DEFAULTS = {
77
'AWS_XRAY_DAEMON_ADDRESS': '127.0.0.1:2000',
88
'AUTO_INSTRUMENT': True,
9-
'AWS_XRAY_CONTEXT_MISSING': 'RUNTIME_ERROR',
9+
'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR',
1010
'PLUGINS': (),
1111
'SAMPLING': True,
1212
'SAMPLING_RULES': None,

docs/frameworks.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The default values are as follows::
3939
XRAY_RECORDER = {
4040
'AWS_XRAY_DAEMON_ADDRESS': '127.0.0.1:2000',
4141
'AUTO_INSTRUMENT': True, # If turned on built-in database queries and template rendering will be recorded as subsegments
42-
'AWS_XRAY_CONTEXT_MISSING': 'RUNTIME_ERROR',
42+
'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR',
4343
'PLUGINS': (),
4444
'SAMPLING': True,
4545
'SAMPLING_RULES': None,

tests/ext/django/test_db.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
@pytest.fixture(scope='module', autouse=True)
1111
def setup():
1212
django.setup()
13-
xray_recorder.configure(context=Context(),
14-
context_missing='LOG_ERROR')
13+
xray_recorder.configure(context=Context())
1514
patch_db()
1615

1716

tests/ext/django/test_middleware.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class XRayTestCase(TestCase):
1515

1616
def setUp(self):
1717
django.setup()
18-
xray_recorder.configure(context=Context(),
19-
context_missing='LOG_ERROR')
18+
xray_recorder.configure(context=Context())
2019
xray_recorder.clear_trace_entities()
2120
global_sdk_config.set_sdk_enabled(True)
2221

tests/test_recorder.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from aws_xray_sdk.core.models.segment import Segment
1414
from aws_xray_sdk.core.models.subsegment import Subsegment
1515
from aws_xray_sdk.core.models.dummy_entities import DummySegment, DummySubsegment
16+
from aws_xray_sdk.core.exceptions.exceptions import SegmentNotFoundException
1617

1718
xray_recorder = get_new_stubbed_recorder()
1819

@@ -99,19 +100,26 @@ def test_put_annotation_metadata():
99100
assert not subsegment.metadata['default'].get('key1')
100101

101102

102-
def test_pass_through_with_missing_context():
103+
def test_default_pass_through_with_missing_context():
103104
xray_recorder = get_new_stubbed_recorder()
104-
xray_recorder.configure(sampling=False, context_missing='LOG_ERROR')
105+
xray_recorder.configure(sampling=False) # default context_missing = 'LOG_ERROR'
105106
assert not xray_recorder.is_sampled()
106107

107108
xray_recorder.put_annotation('key', 'value')
108109
xray_recorder.put_metadata('key', 'value')
109110
xray_recorder.end_segment()
110111

112+
def test_raise_runtime_error_with_missing_context():
113+
xray_recorder = get_new_stubbed_recorder()
114+
xray_recorder.configure(sampling=False, context_missing='RUNTIME_ERROR')
115+
116+
with pytest.raises(SegmentNotFoundException):
117+
assert not xray_recorder.is_sampled()
118+
xray_recorder.end_segment()
111119

112120
def test_capture_not_suppress_exception():
113121
xray_recorder = get_new_stubbed_recorder()
114-
xray_recorder.configure(sampling=False, context_missing='LOG_ERROR')
122+
xray_recorder.configure(sampling=False)
115123

116124
@xray_recorder.capture()
117125
def buggy_func():
@@ -123,7 +131,7 @@ def buggy_func():
123131

124132
def test_capture_not_swallow_return():
125133
xray_recorder = get_new_stubbed_recorder()
126-
xray_recorder.configure(sampling=False, context_missing='LOG_ERROR')
134+
xray_recorder.configure(sampling=False)
127135
value = 1
128136

129137
@xray_recorder.capture()

0 commit comments

Comments
 (0)