|
3 | 3 | from aws_xray_sdk import global_sdk_config
|
4 | 4 | import pytest
|
5 | 5 | from aws_xray_sdk.core import lambda_launcher
|
| 6 | +from aws_xray_sdk.core.models.dummy_entities import DummySegment |
6 | 7 | from aws_xray_sdk.core.models.subsegment import Subsegment
|
7 | 8 |
|
8 | 9 |
|
@@ -85,6 +86,30 @@ def test_non_initialized():
|
85 | 86 |
|
86 | 87 | assert temp_context.get_trace_entity() == subsegment
|
87 | 88 |
|
| 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 | + |
88 | 113 |
|
89 | 114 | def test_set_trace_entity():
|
90 | 115 | segment = context.get_trace_entity()
|
|
0 commit comments