use of com.amazonaws.xray.AWSXRayRecorder in project aws-xray-sdk-java by aws.
the class AWSXRayServletFilter method postFilter.
public void postFilter(ServletRequest request, ServletResponse response) {
AWSXRayRecorder recorder = getRecorder();
Segment segment = recorder.getCurrentSegment();
if (null != segment) {
HttpServletResponse httpServletResponse = castServletResponse(response);
if (null != httpServletResponse) {
Map<String, Object> responseAttributes = new HashMap<String, Object>();
int responseCode = httpServletResponse.getStatus();
switch(responseCode / 100) {
case 4:
segment.setError(true);
if (responseCode == 429) {
segment.setThrottle(true);
}
break;
case 5:
segment.setFault(true);
break;
default:
break;
}
responseAttributes.put("status", responseCode);
Optional<Integer> contentLength = getContentLength(httpServletResponse);
if (contentLength.isPresent()) {
responseAttributes.put("content_length", contentLength.get());
}
segment.putHttp("response", responseAttributes);
}
recorder.endSegment();
}
}
use of com.amazonaws.xray.AWSXRayRecorder in project aws-xray-sdk-java by aws.
the class SimpleSmokeTest method emits.
@Test
void emits() {
AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(emitter).build();
recorder.beginSegment("test");
recorder.endSegment();
verify(emitter, times(1)).sendSegment(any());
}
use of com.amazonaws.xray.AWSXRayRecorder in project aws-xray-sdk-java by aws.
the class TracingInterceptor method beforeExecution.
@Override
public void beforeExecution(Context.BeforeExecution context, ExecutionAttributes executionAttributes) {
AWSXRayRecorder recorder = getRecorder();
Entity origin = recorder.getTraceEntity();
Subsegment subsegment = recorder.beginSubsegment(executionAttributes.getAttribute(SdkExecutionAttribute.SERVICE_NAME));
subsegment.setNamespace(Namespace.AWS.toString());
subsegment.putAws(EntityDataKeys.AWS.OPERATION_KEY, executionAttributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME));
Region region = executionAttributes.getAttribute(AwsExecutionAttribute.AWS_REGION);
if (region != null) {
subsegment.putAws(EntityDataKeys.AWS.REGION_KEY, region.id());
}
subsegment.putAllAws(extractRequestParameters(context, executionAttributes));
if (accountId != null) {
subsegment.putAws(EntityDataKeys.AWS.ACCOUNT_ID_SUBSEGMENT_KEY, accountId);
}
recorder.setTraceEntity(origin);
// store the subsegment in the AWS SDK's executionAttributes so it can be accessed across threads
executionAttributes.putAttribute(entityKey, subsegment);
}
Aggregations