Java Code Examples for com.amazonaws.xray.entities.Subsegment#setError()
The following examples show how to use
com.amazonaws.xray.entities.Subsegment#setError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TracedResponseHandler.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
public static void addResponseInformation(Subsegment subsegment, HttpResponse response) { if (null == subsegment) { return; } Map<String, Object> responseInformation = new HashMap<>(); int responseCode = response.getStatusLine().getStatusCode(); switch (responseCode / 100) { case 4: subsegment.setError(true); if (429 == responseCode) { subsegment.setThrottle(true); } break; case 5: subsegment.setFault(true); break; default: } responseInformation.put("status", responseCode); if (null != response.getEntity()) { responseInformation.put("content_length", response.getEntity().getContentLength()); } subsegment.putHttp("response", responseInformation); }
Example 2
Source File: TracingInterceptor.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
private void populateSubsegmentException(Subsegment subsegment, Context.FailedExecution context) { Throwable exception = context.exception(); subsegment.addException(exception); int statusCode = -1; if (exception instanceof SdkServiceException) { statusCode = ((SdkServiceException) exception).statusCode(); subsegment.getCause().setMessage(exception.getMessage()); if (((SdkServiceException) exception).isThrottlingException()) { subsegment.setThrottle(true); // throttling errors are considered client-side errors subsegment.setError(true); } setRemoteForException(subsegment, exception); } else if (context.httpResponse().isPresent()) { statusCode = context.httpResponse().get().statusCode(); } if (statusCode == -1) { return; } if (statusCode >= 400 && statusCode < 500) { subsegment.setFault(false); subsegment.setError(true); if (statusCode == 429) { subsegment.setThrottle(true); } } else if (statusCode >= 500) { subsegment.setFault(true); } }
Example 3
Source File: TracingHandler.java From aws-xray-sdk-java with Apache License 2.0 | 4 votes |
@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); } } }