Search in sources :

Example 1 with RecordEventsSpanImpl

use of io.opencensus.implcore.trace.RecordEventsSpanImpl in project instrumentation-java by census-instrumentation.

the class InProcessSampledSpanStoreImplTest method getLatencySampledSpans.

@Test
public void getLatencySampledSpans() {
    RecordEventsSpanImpl span = createSampledSpan(REGISTERED_SPAN_NAME);
    testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(20)));
    span.end();
    Collection<SpanData> samples = sampleStore.getLatencySampledSpans(LatencyFilter.create(REGISTERED_SPAN_NAME, TimeUnit.MICROSECONDS.toNanos(15), TimeUnit.MICROSECONDS.toNanos(25), 0));
    assertThat(samples.size()).isEqualTo(1);
    assertThat(samples.contains(span.toSpanData())).isTrue();
}
Also used : SpanData(io.opencensus.trace.export.SpanData) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 2 with RecordEventsSpanImpl

use of io.opencensus.implcore.trace.RecordEventsSpanImpl in project instrumentation-java by census-instrumentation.

the class InProcessSampledSpanStoreImplTest method ignoreNegativeSpanLatency.

@Test
public void ignoreNegativeSpanLatency() {
    RecordEventsSpanImpl span = createSampledSpan(REGISTERED_SPAN_NAME);
    testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(-20)));
    span.end();
    Collection<SpanData> samples = sampleStore.getLatencySampledSpans(LatencyFilter.create(REGISTERED_SPAN_NAME, 0, Long.MAX_VALUE, 0));
    assertThat(samples.size()).isEqualTo(0);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 3 with RecordEventsSpanImpl

use of io.opencensus.implcore.trace.RecordEventsSpanImpl in project instrumentation-java by census-instrumentation.

the class InProcessSampledSpanStoreImplTest method getErrorSampledSpans_MaxSpansToReturn.

@Test
public void getErrorSampledSpans_MaxSpansToReturn() {
    RecordEventsSpanImpl span1 = createSampledSpan(REGISTERED_SPAN_NAME);
    testClock.advanceTime(Duration.create(0, 1000));
    span1.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build());
    // Advance time to allow other spans to be sampled.
    testClock.advanceTime(Duration.create(5, 0));
    RecordEventsSpanImpl span2 = createSampledSpan(REGISTERED_SPAN_NAME);
    testClock.advanceTime(Duration.create(0, 1000));
    span2.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build());
    Collection<SpanData> samples = sampleStore.getErrorSampledSpans(ErrorFilter.create(REGISTERED_SPAN_NAME, CanonicalCode.CANCELLED, 1));
    assertThat(samples.size()).isEqualTo(1);
    // No order guaranteed so one of the spans should be in the list.
    assertThat(samples).containsAnyOf(span1.toSpanData(), span2.toSpanData());
}
Also used : SpanData(io.opencensus.trace.export.SpanData) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 4 with RecordEventsSpanImpl

use of io.opencensus.implcore.trace.RecordEventsSpanImpl in project instrumentation-java by census-instrumentation.

the class InProcessSampledSpanStoreImplTest method getErrorSampledSpans.

@Test
public void getErrorSampledSpans() {
    RecordEventsSpanImpl span = createSampledSpan(REGISTERED_SPAN_NAME);
    testClock.advanceTime(Duration.create(0, 1000));
    span.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build());
    Collection<SpanData> samples = sampleStore.getErrorSampledSpans(ErrorFilter.create(REGISTERED_SPAN_NAME, CanonicalCode.CANCELLED, 0));
    assertThat(samples.size()).isEqualTo(1);
    assertThat(samples.contains(span.toSpanData())).isTrue();
}
Also used : SpanData(io.opencensus.trace.export.SpanData) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 5 with RecordEventsSpanImpl

use of io.opencensus.implcore.trace.RecordEventsSpanImpl in project instrumentation-java by census-instrumentation.

the class SpanExporterImplTest method exportSpansToMultipleServices.

@Test
public void exportSpansToMultipleServices() {
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    TestHandler serviceHandler2 = new TestHandler();
    spanExporter.registerHandler("test.service2", serviceHandler2);
    RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
    List<SpanData> exported1 = serviceHandler.waitForExport(2);
    List<SpanData> exported2 = serviceHandler2.waitForExport(2);
    assertThat(exported1).containsExactly(span1.toSpanData(), span2.toSpanData());
    assertThat(exported2).containsExactly(span1.toSpanData(), span2.toSpanData());
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) TestHandler(io.opencensus.testing.export.TestHandler) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Aggregations

RecordEventsSpanImpl (io.opencensus.implcore.trace.RecordEventsSpanImpl)25 Test (org.junit.Test)21 SpanData (io.opencensus.trace.export.SpanData)18 SimpleEventQueue (io.opencensus.implcore.internal.SimpleEventQueue)6 StartEndHandler (io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler)6 StartEndHandlerImpl (io.opencensus.implcore.trace.StartEndHandlerImpl)6 ArrayList (java.util.ArrayList)2 TestHandler (io.opencensus.testing.export.TestHandler)1