Skip to content

Commit 0411684

Browse files
committed
Renamed config module name to the global name (#129)
sdk_config_module to global_sdk_config Added unit test to test non-initialized lambda context.
1 parent 95bd2c8 commit 0411684

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

aws_xray_sdk/core/lambda_launcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def put_subsegment(self, subsegment):
7171
current_entity = self.get_trace_entity()
7272

7373
if not self._is_subsegment(current_entity) and current_entity.initializing:
74-
if sdk_config_module.sdk_enabled():
74+
if global_sdk_config.sdk_enabled():
7575
log.warning("Subsegment %s discarded due to Lambda worker still initializing" % subsegment.name)
7676
return
7777

tests/test_lambda_context.py

+19
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,22 @@ def test_disable():
6060
global_sdk_config.set_sdk_enabled(False)
6161
segment = context.get_trace_entity()
6262
assert not segment.sampled
63+
64+
65+
def test_non_initialized():
66+
# Context that hasn't been initialized by lambda container should not add subsegments to the facade segment.
67+
temp_header_var = os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
68+
del os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
69+
70+
temp_context = lambda_launcher.LambdaContext()
71+
facade_segment = temp_context.get_trace_entity()
72+
subsegment = Subsegment("TestSubsegment", "local", facade_segment)
73+
temp_context.put_subsegment(subsegment)
74+
75+
assert temp_context.get_trace_entity() == facade_segment
76+
77+
# "Lambda" container added metadata now. Should see subsegment now.
78+
os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY] = temp_header_var
79+
temp_context.put_subsegment(subsegment)
80+
81+
assert temp_context.get_trace_entity() == subsegment

0 commit comments

Comments
 (0)