Search in sources :

Example 1 with Subsegment

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

the class AbstractXRayInterceptor method processXRayTrace.

protected Object processXRayTrace(ProceedingJoinPoint pjp) throws Throwable {
    try {
        Subsegment subsegment = AWSXRay.beginSubsegment(pjp.getSignature().getName());
        subsegment.setMetadata(generateMetadata(pjp, subsegment));
        return XRayInterceptorUtils.conditionalProceed(pjp);
    } catch (Exception e) {
        AWSXRay.getCurrentSegment().addException(e);
        throw e;
    } finally {
        logger.trace("Ending Subsegment");
        AWSXRay.endSubsegment();
    }
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) SegmentNotFoundException(com.amazonaws.xray.exceptions.SegmentNotFoundException)

Example 2 with Subsegment

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

the class AWSXRayRecorderTest method testBeginSubsegmentWhenMissingContext.

@Test
public void testBeginSubsegmentWhenMissingContext() {
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withContextMissingStrategy(new IgnoreErrorContextMissingStrategy()).build();
    Subsegment subsegment = recorder.beginSubsegment("hello");
    assertThat(subsegment).isNotNull();
    assertThat(subsegment.getNamespace()).isEmpty();
    // No-op
    subsegment.setNamespace("foo");
    assertThat(subsegment.getNamespace()).isEmpty();
    assertThat(subsegment.shouldPropagate()).isFalse();
}
Also used : IgnoreErrorContextMissingStrategy(com.amazonaws.xray.strategy.IgnoreErrorContextMissingStrategy) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with Subsegment

use of com.amazonaws.xray.entities.Subsegment 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)

Example 4 with Subsegment

use of com.amazonaws.xray.entities.Subsegment 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 Subsegment

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

the class EntityTest method testManuallySetEntityEndTime.

@Test
public void testManuallySetEntityEndTime() {
    Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", new TraceID());
    Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    segment.addSubsegment(subsegment);
    double endTime = 20.0d;
    segment.setStartTime(1.0);
    subsegment.setStartTime(1.0);
    segment.setEndTime(endTime);
    subsegment.setEndTime(endTime);
    subsegment.end();
    segment.end();
    Assert.assertEquals(endTime, segment.getEndTime(), 0);
    Assert.assertEquals(endTime, subsegment.getEndTime(), 0);
}
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)

Aggregations

Subsegment (com.amazonaws.xray.entities.Subsegment)81 Test (org.junit.Test)35 Segment (com.amazonaws.xray.entities.Segment)31 SubsegmentImpl (com.amazonaws.xray.entities.SubsegmentImpl)14 Test (org.junit.jupiter.api.Test)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)10 SegmentImpl (com.amazonaws.xray.entities.SegmentImpl)10 TraceID (com.amazonaws.xray.entities.TraceID)10 Map (java.util.Map)10 Entity (com.amazonaws.xray.entities.Entity)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 Cause (com.amazonaws.xray.entities.Cause)6 TraceHeader (com.amazonaws.xray.entities.TraceHeader)5 SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)5 Emitter (com.amazonaws.xray.emitters.Emitter)4 SegmentListener (com.amazonaws.xray.listeners.SegmentListener)4 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)4 LambdaAsyncClient (software.amazon.awssdk.services.lambda.LambdaAsyncClient)4