Search in sources :

Example 6 with AWSXRayRecorder

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();
    }
}
Also used : HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) AWSXRayRecorder(com.amazonaws.xray.AWSXRayRecorder) Segment(com.amazonaws.xray.entities.Segment)

Example 7 with AWSXRayRecorder

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());
}
Also used : AWSXRayRecorder(com.amazonaws.xray.AWSXRayRecorder) Test(org.junit.jupiter.api.Test)

Example 8 with AWSXRayRecorder

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);
}
Also used : Entity(com.amazonaws.xray.entities.Entity) Region(software.amazon.awssdk.regions.Region) AWSXRayRecorder(com.amazonaws.xray.AWSXRayRecorder) Subsegment(com.amazonaws.xray.entities.Subsegment)

Aggregations

AWSXRayRecorder (com.amazonaws.xray.AWSXRayRecorder)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Segment (com.amazonaws.xray.entities.Segment)2 SamplingResponse (com.amazonaws.xray.strategy.sampling.SamplingResponse)2 HashMap (java.util.HashMap)2 AsyncContext (javax.servlet.AsyncContext)2 AsyncEvent (javax.servlet.AsyncEvent)2 FilterChain (javax.servlet.FilterChain)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AWSLambda (com.amazonaws.services.lambda.AWSLambda)1 InvokeRequest (com.amazonaws.services.lambda.model.InvokeRequest)1 Entity (com.amazonaws.xray.entities.Entity)1 Subsegment (com.amazonaws.xray.entities.Subsegment)1 TraceHeader (com.amazonaws.xray.entities.TraceHeader)1 SampleDecision (com.amazonaws.xray.entities.TraceHeader.SampleDecision)1 TraceID (com.amazonaws.xray.entities.TraceID)1