Search in sources :

Example 1 with Segment

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

the class ThreadLocalSegmentContext method beginSubsegment.

@Override
public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) {
    Entity current = getTraceEntity();
    if (null == current) {
        recorder.getContextMissingStrategy().contextMissing("Failed to begin subsegment named '" + name + "': segment cannot be found.", SegmentNotFoundException.class);
        return null;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Beginning subsegment named: " + name);
    }
    Segment parentSegment = getTraceEntity().getParentSegment();
    Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment);
    subsegment.setParent(current);
    current.addSubsegment(subsegment);
    setTraceEntity(subsegment);
    return subsegment;
}
Also used : Entity(com.amazonaws.xray.entities.Entity) SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment)

Example 2 with Segment

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

the class AWSXRayRecorderTest method testSetTraceEntityInjectsCurrentSegment.

@Test
public void testSetTraceEntityInjectsCurrentSegment() {
    Segment segment = AWSXRay.beginSegment("test");
    Thread thread = new Thread() {

        public void run() {
            AWSXRay.setTraceEntity(segment);
            Assert.assertEquals(segment, AWSXRay.getTraceEntity());
        }
    };
    thread.start();
    try {
        thread.join();
    } catch (InterruptedException ie) {
    }
    AWSXRay.endSegment();
}
Also used : Segment(com.amazonaws.xray.entities.Segment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with Segment

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

the class AWSXRayRecorderTest method testEmittingSegmentTwiceThrowsSegmentAlreadyEmittedException.

@Test(expected = AlreadyEmittedException.class)
public void testEmittingSegmentTwiceThrowsSegmentAlreadyEmittedException() {
    Segment s = AWSXRay.beginSegment("test");
    AWSXRay.endSegment();
    AWSXRay.injectThreadLocal(s);
    AWSXRay.endSegment();
}
Also used : Segment(com.amazonaws.xray.entities.Segment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with Segment

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

the class EntityTest method testSegmentWithSubsegment.

@Test
public void testSegmentWithSubsegment() throws JSONException {
    TraceID traceId = new TraceID();
    Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
    Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    segment.addSubsegment(subsegment);
    segment.setStartTime(1.0);
    subsegment.setStartTime(1.0);
    subsegment.end();
    segment.end();
    String expected = expectedCompletedSegmentWithSubsegment(traceId, segment.getId(), subsegment.getId(), 1.0, subsegment.getEndTime(), segment.getEndTime()).toString();
    JSONAssert.assertEquals(expected, segment.serialize(), JSONCompareMode.NON_EXTENSIBLE);
}
Also used : TraceID(com.amazonaws.xray.entities.TraceID) SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 5 with Segment

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

the class EntityTest method testInProgressSubsegment.

@Test
public void testInProgressSubsegment() throws JSONException {
    Segment parent = AWSXRay.beginSegment("test");
    Subsegment subsegment = AWSXRay.beginSubsegment("test");
    subsegment.setStartTime(1.0);
    String expected = expectedInProgressSubsegment(parent.getTraceId(), parent.getId(), subsegment.getId(), subsegment.getStartTime()).toString();
    JSONAssert.assertEquals(expected, subsegment.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

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