use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testGetTraceEntityReturnsCurrentSubsegment.
@Test
public void testGetTraceEntityReturnsCurrentSubsegment() {
AWSXRay.beginSegment("test");
Subsegment subsegment = AWSXRay.beginSubsegment("test");
Assert.assertEquals(subsegment, AWSXRay.getTraceEntity());
AWSXRay.endSubsegment();
AWSXRay.endSegment();
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSubsegmentWithChildEmittedTogetherInLambdaContext.
@Test
public void testSubsegmentWithChildEmittedTogetherInLambdaContext() {
TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
Emitter mockEmitter = Mockito.mock(Emitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("testTogether", () -> {
recorder.createSubsegment("testTogether2", () -> {
});
});
ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());
Subsegment captured = emittedSubsegment.getValue();
Assert.assertEquals(1, captured.getSubsegments().size());
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method noOpSubsegmentWithParent.
@Test
public void noOpSubsegmentWithParent() {
TraceID traceID = TraceID.create();
Segment parent = Segment.noOp(traceID, AWSXRay.getGlobalRecorder());
Subsegment subsegment = Subsegment.noOp(parent, AWSXRay.getGlobalRecorder());
assertThat(subsegment.getParentSegment().getTraceId()).isEqualTo(traceID);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testSubsegmentEmittedInLambdaContext.
@Test
public void testSubsegmentEmittedInLambdaContext() throws JSONException {
TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
Emitter mockEmitter = Mockito.mock(Emitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("test", () -> {
});
ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());
Subsegment captured = emittedSubsegment.getValue();
JSONAssert.assertEquals(expectedLambdaSubsegment(header.getRootTraceId(), header.getParentId(), captured.getId(), captured.getStartTime(), captured.getEndTime()).toString(), captured.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testUnsampledSubsegmentPropagation.
@Test
public void testUnsampledSubsegmentPropagation() {
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withSamplingStrategy(new NoSamplingStrategy()).build();
Segment segment = recorder.beginSegmentWithSampling("test");
Subsegment subsegment = recorder.beginSubsegment("test");
assertThat(segment.isSampled()).isFalse();
assertThat(subsegment.shouldPropagate()).isTrue();
}
Aggregations