Search in sources :

Example 11 with Subsegment

use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.

the class TracedResponseHandlerTest method testHandleResponse400SetsErrorFlag.

@Test
public void testHandleResponse400SetsErrorFlag() {
    Segment segment = segmentInResponseToCode(400);
    Subsegment subsegment = segment.getSubsegments().get(0);
    Assert.assertFalse(subsegment.isFault());
    Assert.assertTrue(subsegment.isError());
    Assert.assertFalse(subsegment.isThrottle());
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 12 with Subsegment

use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.

the class TracedResponseHandlerTest method testHandleResponse500SetsFaultFlag.

@Test
public void testHandleResponse500SetsFaultFlag() {
    Segment segment = segmentInResponseToCode(500);
    Subsegment subsegment = segment.getSubsegments().get(0);
    Assert.assertTrue(subsegment.isFault());
    Assert.assertFalse(subsegment.isError());
    Assert.assertFalse(subsegment.isThrottle());
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 13 with Subsegment

use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.

the class TracedResponseHandlerTest method testHandleResponse429SetsErrorAndThrottleFlag.

@Test
public void testHandleResponse429SetsErrorAndThrottleFlag() {
    Segment segment = segmentInResponseToCode(429);
    Subsegment subsegment = segment.getSubsegments().get(0);
    Assert.assertFalse(subsegment.isFault());
    Assert.assertTrue(subsegment.isError());
    Assert.assertTrue(subsegment.isThrottle());
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 14 with Subsegment

use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.

the class TracingHandler method afterResponse.

@Override
public void afterResponse(Request<?> request, Response<?> response) {
    if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
        Optional<Subsegment> currentSubsegmentOptional = recorder.getCurrentSubsegmentOptional();
        if (!currentSubsegmentOptional.isPresent()) {
            return;
        }
        Subsegment currentSubsegment = currentSubsegmentOptional.get();
        populateAndEndSubsegment(currentSubsegment, request, response, null);
    }
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment)

Example 15 with Subsegment

use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.

the class TracingHandler method afterError.

@Override
public void afterError(Request<?> request, Response<?> response, Exception e) {
    if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
        Optional<Subsegment> currentSubsegmentOptional = recorder.getCurrentSubsegmentOptional();
        if (!currentSubsegmentOptional.isPresent()) {
            return;
        }
        Subsegment currentSubsegment = currentSubsegmentOptional.get();
        int statusCode = -1;
        if (null != response) {
            statusCode = response.getHttpResponse().getStatusCode();
        } else {
            if (e instanceof AmazonServiceException) {
                AmazonServiceException ase = (AmazonServiceException) e;
                statusCode = ase.getStatusCode();
                /*
                     * The S3 client will throw and re-swallow AmazonServiceExceptions if they have these status codes. Customers will never see the exceptions in their application code but they still
                     * travel through our TracingHandler#afterError method. We special case these status codes in order to prevent addition of the full exception object to the current subsegment.
                     * Instead, we'll just add any exception error message to the current subsegment's cause's message.
                     */
                if ((304 == statusCode || 412 == statusCode) && S3_SERVICE_NAME.equals(ase.getServiceName())) {
                    populateAndEndSubsegment(currentSubsegment, request, response, ase);
                    return;
                }
                if (RetryUtils.isThrottlingException(ase)) {
                    currentSubsegment.setError(true);
                    currentSubsegment.setThrottle(true);
                }
            }
        }
        if (-1 != statusCode) {
            int statusCodePrefix = statusCode / 100;
            if (4 == statusCodePrefix) {
                currentSubsegment.setError(true);
                if (429 == statusCode) {
                    currentSubsegment.setThrottle(true);
                }
            }
        }
        currentSubsegment.addException(e);
        if (e instanceof AmazonServiceException) {
            populateAndEndSubsegment(currentSubsegment, request, response, (AmazonServiceException) e);
        } else {
            populateAndEndSubsegment(currentSubsegment, request, response);
        }
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) Subsegment(com.amazonaws.xray.entities.Subsegment)

Aggregations

Subsegment (com.amazonaws.xray.entities.Subsegment)27 Segment (com.amazonaws.xray.entities.Segment)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Test (org.junit.Test)7 TraceHeader (com.amazonaws.xray.entities.TraceHeader)4 Emitter (com.amazonaws.xray.emitters.Emitter)3 UDPEmitter (com.amazonaws.xray.emitters.UDPEmitter)3 Entity (com.amazonaws.xray.entities.Entity)3 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)3 SubsegmentImpl (com.amazonaws.xray.entities.SubsegmentImpl)3 TraceID (com.amazonaws.xray.entities.TraceID)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 SegmentImpl (com.amazonaws.xray.entities.SegmentImpl)1 SegmentNotFoundException (com.amazonaws.xray.exceptions.SegmentNotFoundException)1 SubsegmentNotFoundException (com.amazonaws.xray.exceptions.SubsegmentNotFoundException)1 Around (org.aspectj.lang.annotation.Around)1