Skip to content

Commit b266baa

Browse files
committed
[Lambda] Add unit test for lambda passthrough trace header case
1 parent 3be0c9b commit b266baa

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_lambda_context.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ def test_non_initialized():
8585

8686
assert temp_context.get_trace_entity() == subsegment
8787

88+
def test_lambda_passthrough():
89+
# Hold previous environment value
90+
temp_header_var = os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
91+
del os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
92+
93+
# Set header to lambda passthrough style header
94+
os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY] = "Root=%s;Lineage=10:1234abcd:3" % TRACE_ID
95+
96+
temp_context = lambda_launcher.LambdaContext()
97+
dummy_segment = temp_context.get_trace_entity()
98+
subsegment = Subsegment("TestSubsegment", "local", dummy_segment)
99+
temp_context.put_subsegment(subsegment)
100+
101+
# Resulting entity is not the same dummy segment, so compare trace ID
102+
resulting_entity = temp_context.get_trace_entity()
103+
assert TRACE_ID == getattr(resulting_entity, 'traceid', None)
104+
105+
# Reset header value and ensure behaviour returns to normal
106+
del os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
107+
os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY] = temp_header_var
108+
temp_context.put_subsegment(subsegment)
109+
110+
assert temp_context.get_trace_entity() == subsegment
111+
112+
88113

89114
def test_set_trace_entity():
90115
segment = context.get_trace_entity()

0 commit comments

Comments
 (0)