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(UDPEmitter.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 LambdaSegmentContextTest method testLeakedSubsegmentsAreCleanedBetweenInvocations.
@Test
public void testLeakedSubsegmentsAreCleanedBetweenInvocations() {
LambdaSegmentContext lsc = new LambdaSegmentContext();
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(TraceHeader.fromString(TRACE_HEADER));
Subsegment firstInvocation = lsc.beginSubsegment(AWSXRay.getGlobalRecorder(), "test");
Assert.assertNotNull(AWSXRay.getTraceEntity());
PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(TraceHeader.fromString(TRACE_HEADER_2));
Subsegment secondInvocation = lsc.beginSubsegment(AWSXRay.getGlobalRecorder(), "test");
Assert.assertNotNull(AWSXRay.getTraceEntity());
Assert.assertTrue(FacadeSegment.class.isInstance(firstInvocation.getParent()));
Assert.assertTrue(FacadeSegment.class.isInstance(secondInvocation.getParent()));
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class XRaySpringDataInterceptor method traceSQL.
@Around("queryExecution()")
public Object traceSQL(ProceedingJoinPoint pjp) throws Throwable {
try {
Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName());
XRayInterceptorUtils.generateMetadata(pjp, subsegment);
return XRayInterceptorUtils.conditionalProceed(pjp);
} catch (Exception e) {
logger.error(e.getMessage());
AWSXRay.getCurrentSegment().addException(e);
throw e;
} finally {
logger.trace("Ending Subsegment");
AWSXRay.endSubsegment();
}
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracedResponseHandler method handleResponse.
@Override
public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
T handled = wrappedHandler.handleResponse(response);
Subsegment currentSubsegment = AWSXRay.getCurrentSubsegment();
if (null != currentSubsegment) {
TracedResponseHandler.addResponseInformation(currentSubsegment, response);
}
return handled;
}
use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracedResponseHandlerTest method testHandleResponse200SetsNoFlags.
@Test
public void testHandleResponse200SetsNoFlags() {
Segment segment = segmentInResponseToCode(200);
Subsegment subsegment = segment.getSubsegments().get(0);
Assert.assertFalse(subsegment.isFault());
Assert.assertFalse(subsegment.isError());
Assert.assertFalse(subsegment.isThrottle());
}
Aggregations