Skip to content

Commit d174f8d

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

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
@@ -3,6 +3,7 @@
33
from aws_xray_sdk import global_sdk_config
44
import pytest
55
from aws_xray_sdk.core import lambda_launcher
6+
from aws_xray_sdk.core.models.dummy_entities import DummySegment
67
from aws_xray_sdk.core.models.subsegment import Subsegment
78

89

@@ -85,6 +86,30 @@ def test_non_initialized():
8586

8687
assert temp_context.get_trace_entity() == subsegment
8788

89+
def test_lambda_passthrough():
90+
# Hold previous environment value
91+
temp_header_var = os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
92+
del os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY]
93+
94+
# Set header to lambda passthrough style header
95+
os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY] = "Root=%s;Lineage=10:1234abcd:3" % TRACE_ID
96+
97+
temp_context = lambda_launcher.LambdaContext()
98+
dummy_segment = temp_context.get_trace_entity()
99+
subsegment = Subsegment("TestSubsegment", "local", dummy_segment)
100+
temp_context.put_subsegment(subsegment)
101+
102+
# Resulting entity is not the same dummy segment, so simply check that it is a dummy segment
103+
assert isinstance(temp_context.get_trace_entity(), DummySegment)
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)