Search in sources :

Example 21 with Segment

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

the class EntityTest method testModifyingSegmentAfterEndingThrowsAlreadyEmittedException.

@SuppressWarnings("resource")
@Test(expected = AlreadyEmittedException.class)
public void testModifyingSegmentAfterEndingThrowsAlreadyEmittedException() {
    TraceID traceId = new TraceID();
    Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
    segment.end();
    segment.setStartTime(1.0);
}
Also used : TraceID(com.amazonaws.xray.entities.TraceID) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 22 with Segment

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

the class CustomSegmentContextTest method testGlobalMapSegmentContext.

@Test
public void testGlobalMapSegmentContext() {
    Segment test = AWSXRay.beginSegment("test");
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        list.add(new Integer(i));
    }
    list.parallelStream().forEach(e -> {
        AWSXRay.setTraceEntity(test);
        AWSXRay.createSubsegment("parallelPrint", (subsegment) -> {
        });
    });
    Assert.assertEquals(100, test.getTotalSize().intValue());
    AWSXRay.endSegment();
}
Also used : ArrayList(java.util.ArrayList) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 23 with Segment

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

the class AWSXRayServletFilterTest method testNameOverrideSystemProperty.

@Test
public void testNameOverrideSystemProperty() throws IOException, ServletException {
    System.setProperty(SegmentNamingStrategy.NAME_OVERRIDE_SYSTEM_PROPERTY_KEY, "pass");
    AWSXRayServletFilter servletFilter = new AWSXRayServletFilter("fail");
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
    Mockito.when(request.getMethod()).thenReturn("TEST_METHOD");
    Mockito.when(request.isAsyncStarted()).thenReturn(false);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    FilterChain chain = Mockito.mock(FilterChain.class);
    servletFilter.doFilter(request, response, chain);
    ArgumentCaptor<Segment> emittedSegment = ArgumentCaptor.forClass(Segment.class);
    Mockito.verify(AWSXRay.getGlobalRecorder().getEmitter(), Mockito.times(1)).sendSegment(emittedSegment.capture());
    Assert.assertEquals("pass", emittedSegment.getValue().getName());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 24 with Segment

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

the class AbstractXRayInterceptor method getCurrentSegment.

private static Segment getCurrentSegment() {
    Optional<Segment> segment = getCurrentSegmentOptional();
    if (segment.isPresent()) {
        return segment.get();
    }
    ContextMissingStrategy contextMissingStrategy = getContextMissingStrategy();
    contextMissingStrategy.contextMissing("No segment in progress.", SegmentNotFoundException.class);
    return null;
}
Also used : Segment(com.amazonaws.xray.entities.Segment) ContextMissingStrategy(com.amazonaws.xray.strategy.ContextMissingStrategy)

Example 25 with Segment

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

the class TracedHttpClient method addRequestInformation.

public static void addRequestInformation(Subsegment subsegment, HttpRequest request, String url) {
    subsegment.setNamespace(Namespace.REMOTE.toString());
    Segment parentSegment = subsegment.getParentSegment();
    TraceHeader header = new TraceHeader(parentSegment.getTraceId(), parentSegment.isSampled() ? subsegment.getId() : null, parentSegment.isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED);
    request.addHeader(TraceHeader.HEADER_KEY, header.toString());
    Map<String, Object> requestInformation = new HashMap<>();
    requestInformation.put("url", url);
    requestInformation.put("method", request.getRequestLine().getMethod());
    subsegment.putHttp("request", requestInformation);
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) HashMap(java.util.HashMap) Segment(com.amazonaws.xray.entities.Segment)

Aggregations

Segment (com.amazonaws.xray.entities.Segment)29 Test (org.junit.Test)16 Subsegment (com.amazonaws.xray.entities.Subsegment)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 TraceID (com.amazonaws.xray.entities.TraceID)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 SegmentImpl (com.amazonaws.xray.entities.SegmentImpl)4 SubsegmentImpl (com.amazonaws.xray.entities.SubsegmentImpl)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 HashMap (java.util.HashMap)3 FilterChain (javax.servlet.FilterChain)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 TraceHeader (com.amazonaws.xray.entities.TraceHeader)2 AWSLambda (com.amazonaws.services.lambda.AWSLambda)1 InvokeRequest (com.amazonaws.services.lambda.model.InvokeRequest)1 InvokeResult (com.amazonaws.services.lambda.model.InvokeResult)1 Emitter (com.amazonaws.xray.emitters.Emitter)1 UDPEmitter (com.amazonaws.xray.emitters.UDPEmitter)1