Search in sources :

Example 21 with RecordEventsSpanImpl

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

the class InProcessRunningSpanStoreImplTest method getSummary_SpansWithSameName.

@Test
public void getSummary_SpansWithSameName() {
    final RecordEventsSpanImpl span1 = createSpan(SPAN_NAME_1);
    final RecordEventsSpanImpl span2 = createSpan(SPAN_NAME_1);
    final RecordEventsSpanImpl span3 = createSpan(SPAN_NAME_1);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(1);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().get(SPAN_NAME_1).getNumRunningSpans()).isEqualTo(3);
    span1.end();
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(1);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().get(SPAN_NAME_1).getNumRunningSpans()).isEqualTo(2);
    span2.end();
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(1);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().get(SPAN_NAME_1).getNumRunningSpans()).isEqualTo(1);
    span3.end();
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(0);
}
Also used : RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 22 with RecordEventsSpanImpl

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

Example 23 with RecordEventsSpanImpl

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

the class SpanExporterImplTest method serviceHandlerThrowsException.

@Test
public void serviceHandlerThrowsException() {
    doThrow(new IllegalArgumentException("No export for you.")).when(mockServiceHandler).export(ArgumentMatchers.<SpanData>anyList());
    SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
    StartEndHandler startEndHandler = new StartEndHandlerImpl(spanExporter, runningSpanStore, sampledSpanStore, new SimpleEventQueue());
    spanExporter.registerHandler("test.service", serviceHandler);
    spanExporter.registerHandler("mock.service", mockServiceHandler);
    RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    List<SpanData> exported = serviceHandler.waitForExport(1);
    assertThat(exported).containsExactly(span1.toSpanData());
    // Continue to export after the exception was received.
    RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    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 24 with RecordEventsSpanImpl

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

the class SpanExporterImplTest method exportMoreSpansThanTheBufferSize.

@Test
public void exportMoreSpansThanTheBufferSize() {
    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_1);
    RecordEventsSpanImpl span3 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span4 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span5 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    RecordEventsSpanImpl span6 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
    List<SpanData> exported = serviceHandler.waitForExport(6);
    assertThat(exported).containsExactly(span1.toSpanData(), span2.toSpanData(), span3.toSpanData(), span4.toSpanData(), span5.toSpanData(), span6.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 25 with RecordEventsSpanImpl

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

the class SpanExporterImplTest method createSampledEndedSpan.

private RecordEventsSpanImpl createSampledEndedSpan(StartEndHandler startEndHandler, String spanName) {
    RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(sampledSpanContext, spanName, null, null, false, TraceParams.DEFAULT, startEndHandler, null, MillisClock.getInstance());
    span.end();
    return span;
}
Also used : RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl)

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