use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class LambdaSegmentContext method endSubsegment.
@Override
public void endSubsegment(AWSXRayRecorder recorder) {
Entity current = getTraceEntity();
if (current instanceof Subsegment) {
if (logger.isDebugEnabled()) {
logger.debug("Ending subsegment named: " + current.getName());
}
Subsegment currentSubsegment = (Subsegment) current;
currentSubsegment.end();
if (recorder.getStreamingStrategy().requiresStreaming(currentSubsegment.getParentSegment())) {
recorder.getStreamingStrategy().streamSome(currentSubsegment.getParentSegment(), recorder.getEmitter());
}
Entity parentEntity = current.getParent();
if (parentEntity instanceof FacadeSegment) {
if (((FacadeSegment) parentEntity).isSampled()) {
current.getCreator().getEmitter().sendSubsegment((Subsegment) current);
}
clearTraceEntity();
} else {
setTraceEntity(current.getParent());
}
} else {
throw new SubsegmentNotFoundException("Failed to end a subsegment: subsegment cannot be found.");
}
}
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(UDPEmitter.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 testSubsequentSubsegmentBranchesEmittedInLambdaContext.
@Test
public void testSubsequentSubsegmentBranchesEmittedInLambdaContext() {
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(UDPEmitter.class);
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
recorder.createSubsegment("testTogether", () -> {
recorder.createSubsegment("testTogether2", () -> {
});
});
recorder.createSubsegment("testTogether3", () -> {
recorder.createSubsegment("testTogether4", () -> {
});
});
ArgumentCaptor<Subsegment> emittedSubsegments = ArgumentCaptor.forClass(Subsegment.class);
Mockito.verify(mockEmitter, Mockito.times(2)).sendSubsegment(emittedSubsegments.capture());
List<Subsegment> captured = emittedSubsegments.getAllValues();
captured.forEach((capturedSubsegment) -> {
Assert.assertEquals(1, capturedSubsegment.getSubsegments().size());
});
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class AWSXRayRecorderTest method testGetThreadLocalReturnsCurrentSubsegment.
@Test
public void testGetThreadLocalReturnsCurrentSubsegment() {
AWSXRay.beginSegment("test");
Subsegment subsegment = AWSXRay.beginSubsegment("test");
Assert.assertEquals(subsegment, AWSXRay.getThreadLocal());
AWSXRay.endSubsegment();
AWSXRay.endSegment();
}
Aggregations