Skip to content

Commit

Permalink
Change context missing strategy behaviour to Log Error (#83)
Browse files Browse the repository at this point in the history
* Change default context missing strategy to log error

* update tests

* test case feedback

Co-authored-by: Jonathan Lee <jjllee@amazon.com>
  • Loading branch information
jj22ee and jj22ee authored Jan 20, 2023
1 parent 046711a commit 2e2e2ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/aws-xray-sdk/context/default_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DefaultContext
LOCAL_KEY = '_aws_xray_entity'.freeze
CONTEXT_MISSING_KEY = 'AWS_XRAY_CONTEXT_MISSING'.freeze
SUPPORTED_STRATEGY = %w[RUNTIME_ERROR LOG_ERROR IGNORE_ERROR].freeze
DEFAULT_STRATEGY = SUPPORTED_STRATEGY[0]
DEFAULT_STRATEGY = SUPPORTED_STRATEGY[1]

attr_reader :context_missing

Expand Down
13 changes: 10 additions & 3 deletions test/aws-xray-sdk/tc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ def test_segment_crud
def test_change_context_missing
context = XRay::DefaultContext.new
context.clear!
context.context_missing = 'UNKWON'
assert_equal 'RUNTIME_ERROR', context.context_missing
context.context_missing = 'LOG_ERROR'
context.context_missing = 'INVALID_STRATEGY'
assert_equal 'LOG_ERROR', context.context_missing
context.context_missing = 'RUNTIME_ERROR'
assert_equal 'RUNTIME_ERROR', context.context_missing
end

def test_runtime_error
context = XRay::DefaultContext.new
context.clear!
context.context_missing = 'RUNTIME_ERROR'
assert_raises XRay::ContextMissingError do
context.current_entity
end
Expand All @@ -39,4 +40,10 @@ def test_log_error
context.context_missing = 'LOG_ERROR'
refute context.current_entity
end

def test_default_context_missing
context = XRay::DefaultContext.new
context.clear!
refute context.current_entity
end
end
17 changes: 16 additions & 1 deletion test/aws-xray-sdk/tc_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,23 @@ def test_send_segment
segment = @@recorder.begin_segment name: name
@@recorder.end_segment
assert_equal segment, @@recorder.emitter.entities[0]
end

def test_send_segment_with_ctx_missing_runtime_error
recorder = XRay::Recorder.new
config = {
context_missing: 'RUNTIME_ERROR',
sampling: false,
emitter: XRay::TestHelper::StubbedEmitter.new,
sampler: XRay::TestHelper::StubbedDefaultSampler.new
}
recorder.configure(config)

segment = recorder.begin_segment name: name
recorder.end_segment
assert_equal segment, recorder.emitter.entities[0]
assert_raises XRay::ContextMissingError do
@@recorder.current_segment
recorder.current_segment
end
end

Expand Down

0 comments on commit 2e2e2ef

Please sign in to comment.