Search in sources :

Example 1 with StartEndHandlerImpl

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

the class SpanExporterImplTest method exportMoreSpansThanTheMaximumLimit.

@Test
public void exportMoreSpansThanTheMaximumLimit() {
    final int bufferSize = 4;
    final int maxReferencedSpans = bufferSize * 4;
    SpanExporterImpl spanExporter = SpanExporterImpl.create(bufferSize, Duration.create(1, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    BlockingExporter blockingExporter = new BlockingExporter();
    spanExporter.registerHandler("test.service", serviceHandler);
    spanExporter.registerHandler("test.blocking", blockingExporter);
    List<SpanData> spansToExport = new ArrayList<>(maxReferencedSpans);
    for (int i = 0; i < maxReferencedSpans; i++) {
        spansToExport.add(createSampledEndedSpan(startEndHandler, "span_1_" + i).toSpanData());
    }
    assertThat(spanExporter.getReferencedSpans()).isEqualTo(maxReferencedSpans);
    // Now we should start dropping.
    for (int i = 0; i < 7; i++) {
        createSampledEndedSpan(startEndHandler, "span_2_" + i);
        assertThat(spanExporter.getDroppedSpans()).isEqualTo(i + 1);
    }
    assertThat(spanExporter.getReferencedSpans()).isEqualTo(maxReferencedSpans);
    // Release the blocking exporter
    blockingExporter.unblock();
    List<SpanData> exported = serviceHandler.waitForExport(maxReferencedSpans);
    assertThat(exported).isNotNull();
    assertThat(exported).containsExactlyElementsIn(spansToExport);
    exported.clear();
    spansToExport.clear();
    // We cannot compare with maxReferencedSpans here because the worker thread may get
    // unscheduled immediately after exporting, but before updating the pushed spans, if that is
    // the case at most bufferSize spans will miss.
    assertThat(spanExporter.getPushedSpans()).isAtLeast((long) maxReferencedSpans - bufferSize);
    for (int i = 0; i < 7; i++) {
        spansToExport.add(createSampledEndedSpan(startEndHandler, "span_3_" + i).toSpanData());
        // No more dropped spans.
        assertThat(spanExporter.getDroppedSpans()).isEqualTo(7);
    }
    exported = serviceHandler.waitForExport(7);
    assertThat(exported).isNotNull();
    assertThat(exported).containsExactlyElementsIn(spansToExport);
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) ArrayList(java.util.ArrayList) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) Test(org.junit.Test)

Example 2 with StartEndHandlerImpl

use of io.opencensus.implcore.trace.StartEndHandlerImpl 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)

Example 3 with StartEndHandlerImpl

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

the class SpanExporterImplTest method exportNotSampledSpans.

@Test
public void exportNotSampledSpans() {
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    RecordEventsSpanImpl span1 = createNotSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
    // Spans are recorded and exported in the same order as they are ended, we test that a non
    // sampled span is not exported by creating and ending a sampled span after a non sampled span
    // and checking that the first exported span is the sampled span (the non sampled did not get
    // exported).
    List<SpanData> exported = serviceHandler.waitForExport(1);
    // Need to check this because otherwise the variable span1 is unused, other option is to not
    // have a span1 variable.
    assertThat(exported).doesNotContain(span1.toSpanData());
    assertThat(exported).containsExactly(span2.toSpanData());
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 4 with StartEndHandlerImpl

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

the class SpanExporterImplTest method exportNotSampledSpansFlushed.

@Test(timeout = 10000L)
public void exportNotSampledSpansFlushed() {
    // Set the export delay to zero, for no timeout, in order to confirm the #flush() below works
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(0, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
    // Force a flush, without this, the #waitForExport() call below would block indefinitely.
    spanExporter.flush();
    List<SpanData> exported = serviceHandler.waitForExport(1);
    assertThat(exported).containsExactly(span2.toSpanData());
}
Also used : StartEndHandler(io.opencensus.implcore.trace.RecordEventsSpanImpl.StartEndHandler) SpanData(io.opencensus.trace.export.SpanData) StartEndHandlerImpl(io.opencensus.implcore.trace.StartEndHandlerImpl) SimpleEventQueue(io.opencensus.implcore.internal.SimpleEventQueue) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 5 with StartEndHandlerImpl

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

the class SpanExporterImplTest method exportDifferentSampledSpans.

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

Aggregations

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