Skip to content
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

add xray sdk language and version in subsegment from Lambda environment #406

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) {
? new SubsegmentImpl(recorder, name, parentSegment)
: Subsegment.noOp(parentSegment, recorder);
subsegment.setParent(parentSegment);
subsegment.putAllAws(recorder.getAwsRuntimeContext());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user creates multiple "root subsegments", looks like each will have a copy of this information.
Do we want only one of the subsegments to have this information?
I don't know which is more reasonable: one or all subsegments with this data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding this information to all subsegments and not just "root subsegments" (not sure @jj22ee what you mean by this), right?
So it seem redundant to add same information to all the subsegments. Can we possibly add this to the segment created by Lambda runtime?

// Enable FacadeSegment to keep track of its subsegments for subtree streaming
parentSegment.addSubsegment(subsegment);
setTraceEntity(subsegment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void testSubsegmentEmittedInLambdaContext() throws JSONException {

JSONAssert.assertEquals(expectedLambdaSubsegment(
header.getRootTraceId(), header.getParentId(), captured.getId(), captured.getStartTime(),
captured.getEndTime()).toString(), captured.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
captured.getEndTime()).toString(), captured.streamSerialize(), JSONCompareMode.LENIENT);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ void testEndSubsegmentUsesContextMissing() {
assertThatThrownBy(AWSXRay::endSubsegment).isInstanceOf(SubsegmentNotFoundException.class);
}

@Test
@SetEnvironmentVariable(key = "_X_AMZN_TRACE_ID", value = TRACE_HEADER)
void testSampledSetsAwsXRaySdkVersionToSubsegment() {
LambdaSegmentContext lsc = new LambdaSegmentContext();
Subsegment subseg1 = lsc.beginSubsegment(AWSXRay.getGlobalRecorder(), "test");
Subsegment subseg2 = lsc.beginSubsegment(AWSXRay.getGlobalRecorder(), "test2");
assertThat(subseg1.getAws().get("xray")).isNotNull();
assertThat(subseg2.getAws().get("xray")).isNull();
lsc.endSubsegment(AWSXRay.getGlobalRecorder());
lsc.endSubsegment(AWSXRay.getGlobalRecorder());
}

// We create segments twice with different environment variables for the same context, similar to how Lambda would invoke
// a function.
@Nested
Expand Down
Loading