Skip to content

[LambdaContext] persist original trace header #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws_xray_sdk/core/lambda_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ def _initialize_context(self, trace_header):
entityid=trace_header.parent,
sampled=sampled,
)
segment.save_origin_trace_header(trace_header)
setattr(self._local, 'segment', segment)
setattr(self._local, 'entities', [])
6 changes: 5 additions & 1 deletion tests/test_lambda_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

TRACE_ID = '1-5759e988-bd862e3fe1be46a994272793'
PARENT_ID = '53995c3f42cd8ad8'
HEADER_VAR = "Root=%s;Parent=%s;Sampled=1" % (TRACE_ID, PARENT_ID)
DATA = 'Foo=Bar'
HEADER_VAR = "Root=%s;Parent=%s;Sampled=1;%s" % (TRACE_ID, PARENT_ID, DATA)

os.environ[lambda_launcher.LAMBDA_TRACE_HEADER_KEY] = HEADER_VAR
context = lambda_launcher.LambdaContext()
Expand All @@ -26,6 +27,7 @@ def test_facade_segment_generation():
assert segment.id == PARENT_ID
assert segment.trace_id == TRACE_ID
assert segment.sampled
assert DATA in segment.get_origin_trace_header().to_header_str()


def test_put_subsegment():
Expand All @@ -43,6 +45,7 @@ def test_put_subsegment():
assert subsegment2.parent_id == subsegment.id
assert subsegment.parent_id == segment.id
assert subsegment2.parent_segment is segment
assert DATA in subsegment2.parent_segment.get_origin_trace_header().to_header_str()

context.end_subsegment()
assert context.get_trace_entity().id == subsegment.id
Expand All @@ -60,6 +63,7 @@ def test_disable():
global_sdk_config.set_sdk_enabled(False)
segment = context.get_trace_entity()
assert not segment.sampled
assert DATA in segment.get_origin_trace_header().to_header_str()


def test_non_initialized():
Expand Down