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());
}
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());
}
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());
}
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);
}
}
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);
}
}
}
Aggregations