Java Code Examples for com.amazonaws.xray.AWSXRay#getGlobalRecorder()

The following examples show how to use com.amazonaws.xray.AWSXRay#getGlobalRecorder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultStreamingStrategyTest.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testingBasicStreamingFunctionality() {
    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
    TraceID traceId = new TraceID();

    Segment segment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceId);
    Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    Subsegment subsegment1 = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", segment);
    segment.addSubsegment(subsegment);
    segment.addSubsegment(subsegment1);

    segment.setStartTime(1.0);
    subsegment.setStartTime(1.0);
    subsegment1.setStartTime(1.0);

    subsegment.end();

    defaultStreamingStrategy.streamSome(segment, AWSXRay.getGlobalRecorder().getEmitter());
    Assert.assertTrue(segment.getTotalSize().intValue() == 1);
}
 
Example 2
Source File: DefaultStreamingStrategyTest.java    From aws-xray-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreamSomeChildrenRemovedFromParent() {
    TraceID traceId = new TraceID();
    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);

    Segment bigSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "big", traceId);
    bigSegment.setStartTime(1.0);

    for (int i = 0; i < 5; i++) {
        Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "child" + i, bigSegment);
        subsegment.setStartTime(1.0);
        bigSegment.addSubsegment(subsegment);
        subsegment.end();
    }
    Assert.assertTrue(defaultStreamingStrategy.requiresStreaming(bigSegment));
    defaultStreamingStrategy.streamSome(bigSegment, AWSXRay.getGlobalRecorder().getEmitter());
    Assert.assertTrue(bigSegment.getTotalSize().intValue() == 0);
}
 
Example 3
Source File: SLF4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetPrefix() {
    SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);

    listener.onSetEntity(null, seg);

    Assert.assertEquals(traceID.toString() + "@" + seg.getId(), MDC.get(TRACE_ID_KEY));
}
 
Example 4
Source File: DefaultStreamingStrategyTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultStreamingStrategyRequiresStreaming() {
    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);

    Segment smallSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "small");
    Assert.assertFalse(defaultStreamingStrategy.requiresStreaming(smallSegment));

    Segment bigSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "big");
    bigSegment.addSubsegment(new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child", bigSegment));
    bigSegment.addSubsegment(new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child", bigSegment));
    Assert.assertTrue(defaultStreamingStrategy.requiresStreaming(bigSegment));
}
 
Example 5
Source File: DefaultStreamingStrategyTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testBushyandSpindlySegmentTreeStreaming() {
    TraceID traceId = new TraceID();

    Segment bigSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "big", traceId);
    bigSegment.setStartTime(1.0);

    for (int i = 0; i < 5; i++) {
        Subsegment subsegment = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "child" + i, bigSegment);
        subsegment.setStartTime(1.0);
        bigSegment.addSubsegment(subsegment);
        subsegment.end();
    }

    SubsegmentImpl holder = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child0", bigSegment);
    holder.setStartTime(1.0);
    bigSegment.addSubsegment(holder);
    holder.end();

    SubsegmentImpl holder1 = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child1", bigSegment);
    holder1.setStartTime(1.0);
    bigSegment.addSubsegment(holder1);
    holder1.end();

    SubsegmentImpl holder2 = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child2", bigSegment);
    holder2.setStartTime(1.0);
    bigSegment.addSubsegment(holder2);
    holder2.end();

    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
    Assert.assertTrue(defaultStreamingStrategy.requiresStreaming(bigSegment));
    defaultStreamingStrategy.streamSome(bigSegment, AWSXRay.getGlobalRecorder().getEmitter());
    Assert.assertTrue(bigSegment.getReferenceCount() == 0);
}
 
Example 6
Source File: SLF4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedSubsegmentInjection() {
    SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);
    listener.onSetEntity(null, seg);
    Subsegment sub1 = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test1", seg);
    listener.onSetEntity(seg, sub1);
    Subsegment sub2 = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test2", seg);
    listener.onSetEntity(sub1, sub2);

    Assert.assertEquals(traceID.toString() + "@" + sub2.getId(), MDC.get(TRACE_ID_KEY));
}
 
Example 7
Source File: SLF4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubsegmentInjection() {
    SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);
    listener.onSetEntity(null, seg);
    Subsegment sub = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", seg);
    listener.onSetEntity(seg, sub);

    Assert.assertEquals(traceID.toString() + "@" + sub.getId(), MDC.get(TRACE_ID_KEY));
}
 
Example 8
Source File: SLF4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsampledSegmentInjection() {
    SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);
    seg.setSampled(false);
    listener.onSetEntity(null, seg);

    Assert.assertNull(MDC.get(TRACE_ID_KEY));
}
 
Example 9
Source File: SLF4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSegmentInjection() {
    SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);
    listener.onSetEntity(null, seg);

    Assert.assertEquals(traceID.toString() + "@" + seg.getId(), MDC.get(TRACE_ID_KEY));
}
 
Example 10
Source File: SLF4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultPrefix() {
    SLF4JSegmentListener listener = (SLF4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", traceID);

    listener.onSetEntity(null, seg);

    Assert.assertEquals(TRACE_ID_KEY + ": " + traceID.toString() + "@" + seg.getId(), MDC.get(TRACE_ID_KEY));
}
 
Example 11
Source File: Log4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubsegmentInjection() {
    Log4JSegmentListener listener = (Log4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", TRACE_ID);
    listener.onSetEntity(null, seg);
    Subsegment sub = new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "test", seg);
    listener.onSetEntity(seg, sub);

    Assert.assertEquals(TRACE_ID.toString() + "@" + sub.getId(), ThreadContext.get(TRACE_ID_KEY));
}
 
Example 12
Source File: Log4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsampledSegmentInjection() {
    Log4JSegmentListener listener = (Log4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", TRACE_ID);
    seg.setSampled(false);
    listener.onSetEntity(null, seg);

    Assert.assertNull(ThreadContext.get(TRACE_ID_KEY));
}
 
Example 13
Source File: Log4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSegmentInjection() {
    Log4JSegmentListener listener = (Log4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    listener.setPrefix("");
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", TRACE_ID);
    listener.onSetEntity(null, seg);

    Assert.assertEquals(TRACE_ID.toString() + "@" + seg.getId(), ThreadContext.get(TRACE_ID_KEY));
}
 
Example 14
Source File: Log4JSegmentListenerTest.java    From aws-xray-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultPrefix() {
    Log4JSegmentListener listener = (Log4JSegmentListener) AWSXRay.getGlobalRecorder().getSegmentListeners().get(0);
    Segment seg = new SegmentImpl(AWSXRay.getGlobalRecorder(), "test", TRACE_ID);

    listener.onSetEntity(null, seg);

    Assert.assertEquals(TRACE_ID_KEY + ": " + TRACE_ID.toString() + "@" + seg.getId(), ThreadContext.get(TRACE_ID_KEY));
}
 
Example 15
Source File: TracingHandler.java    From aws-xray-sdk-java with Apache License 2.0 4 votes vote down vote up
private void lazyLoadRecorder() {
    if (recorder != null) {
        return;
    }
    recorder = AWSXRay.getGlobalRecorder();
}
 
Example 16
Source File: AWSXRayServletAsyncListener.java    From aws-xray-sdk-java with Apache License 2.0 4 votes vote down vote up
private AWSXRayRecorder getRecorder() {
    if (recorder == null) {
        recorder = AWSXRay.getGlobalRecorder();
    }
    return recorder;
}
 
Example 17
Source File: TracingInterceptor.java    From aws-xray-sdk-java with Apache License 2.0 4 votes vote down vote up
private AWSXRayRecorder getRecorder() {
    if (recorder == null) {
        recorder = AWSXRay.getGlobalRecorder();
    }
    return recorder;
}
 
Example 18
Source File: DefaultStreamingStrategyTest.java    From aws-xray-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefaultStreamingStrategyDoesNotRequireStreaming() {
    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
    Segment smallSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "small");
    Assert.assertFalse(defaultStreamingStrategy.requiresStreaming(smallSegment));
}
 
Example 19
Source File: TracingHandler.java    From aws-xray-sdk-java with Apache License 2.0 4 votes vote down vote up
public TracingHandler(String accountId, URL operationParameterWhitelist) {
    this(AWSXRay.getGlobalRecorder(), accountId, operationParameterWhitelist);
}
 
Example 20
Source File: TracedHttpClient.java    From aws-xray-sdk-java with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a TracedHttpClient instance using the provided client and global recorder.
 *
 * @param wrappedClient
 *            the HTTP client to wrap
 */
public TracedHttpClient(final CloseableHttpClient wrappedClient) {
    this(wrappedClient, AWSXRay.getGlobalRecorder());
}