Search in sources :

Example 6 with TraceHeader

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

the class AWSXRayRecorderTest method testSubsegmentWithChildEmittedTogetherInLambdaContext.

@Test
public void testSubsegmentWithChildEmittedTogetherInLambdaContext() {
    TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
    Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
    recorder.createSubsegment("testTogether", () -> {
        recorder.createSubsegment("testTogether2", () -> {
        });
    });
    ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
    Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());
    Subsegment captured = emittedSubsegment.getValue();
    Assert.assertEquals(1, captured.getSubsegments().size());
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) UDPEmitter(com.amazonaws.xray.emitters.UDPEmitter) Emitter(com.amazonaws.xray.emitters.Emitter) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with TraceHeader

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

the class AWSXRayRecorderTest method testSubsequentSubsegmentBranchesEmittedInLambdaContext.

@Test
public void testSubsequentSubsegmentBranchesEmittedInLambdaContext() {
    TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
    Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
    recorder.createSubsegment("testTogether", () -> {
        recorder.createSubsegment("testTogether2", () -> {
        });
    });
    recorder.createSubsegment("testTogether3", () -> {
        recorder.createSubsegment("testTogether4", () -> {
        });
    });
    ArgumentCaptor<Subsegment> emittedSubsegments = ArgumentCaptor.forClass(Subsegment.class);
    Mockito.verify(mockEmitter, Mockito.times(2)).sendSubsegment(emittedSubsegments.capture());
    List<Subsegment> captured = emittedSubsegments.getAllValues();
    captured.forEach((capturedSubsegment) -> {
        Assert.assertEquals(1, capturedSubsegment.getSubsegments().size());
    });
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) UDPEmitter(com.amazonaws.xray.emitters.UDPEmitter) Emitter(com.amazonaws.xray.emitters.Emitter) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with TraceHeader

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

the class AWSXRayRecorderTest method testSubsegmentEmittedInLambdaContext.

@Test
public void testSubsegmentEmittedInLambdaContext() throws JSONException {
    TraceHeader header = TraceHeader.fromString(TRACE_HEADER);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");
    Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
    recorder.createSubsegment("test", () -> {
    });
    ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
    Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());
    Subsegment captured = emittedSubsegment.getValue();
    JSONAssert.assertEquals(expectedLambdaSubsegment(header.getRootTraceId(), header.getParentId(), captured.getId(), captured.getStartTime(), captured.getEndTime()).toString(), captured.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) UDPEmitter(com.amazonaws.xray.emitters.UDPEmitter) Emitter(com.amazonaws.xray.emitters.Emitter) Subsegment(com.amazonaws.xray.entities.Subsegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with TraceHeader

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

the class TraceHeaderTest method testLongHeaderToString.

@Test
public void testLongHeaderToString() {
    TraceHeader header = new TraceHeader();
    header.setSampled(SampleDecision.SAMPLED);
    header.setRootTraceId(TraceID.fromString(TRACE_ID));
    header.setParentId("foo");
    header.getAdditionalParams().put("Foo", "bar");
    Assert.assertEquals("Root=" + TRACE_ID + ";Parent=foo;Sampled=1;Foo=bar", header.toString());
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) Test(org.junit.Test)

Example 10 with TraceHeader

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

the class TraceHeaderTest method testSampledEqualsOneFromString.

@Test
public void testSampledEqualsOneFromString() {
    TraceHeader header = TraceHeader.fromString("Sampled=1");
    Assert.assertEquals(SampleDecision.SAMPLED, header.getSampled());
    Assert.assertNull(header.getRootTraceId());
    Assert.assertNull(header.getParentId());
    Assert.assertTrue(header.getAdditionalParams().isEmpty());
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) Test(org.junit.Test)

Aggregations

TraceHeader (com.amazonaws.xray.entities.TraceHeader)13 Test (org.junit.Test)7 Subsegment (com.amazonaws.xray.entities.Subsegment)4 Emitter (com.amazonaws.xray.emitters.Emitter)3 UDPEmitter (com.amazonaws.xray.emitters.UDPEmitter)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Segment (com.amazonaws.xray.entities.Segment)2 HashMap (java.util.HashMap)2 Entity (com.amazonaws.xray.entities.Entity)1 SampleDecision (com.amazonaws.xray.entities.TraceHeader.SampleDecision)1 TraceID (com.amazonaws.xray.entities.TraceID)1 SamplingStrategy (com.amazonaws.xray.strategy.sampling.SamplingStrategy)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1