Search in sources :

Example 16 with RecordEventsSpanImpl

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

the class InProcessSampledSpanStoreImplTest method getLatencySampledSpans_QueryBetweenMultipleBuckets.

@Test
public void getLatencySampledSpans_QueryBetweenMultipleBuckets() {
    RecordEventsSpanImpl span1 = createSampledSpan(REGISTERED_SPAN_NAME);
    testClock.advanceTime(Duration.create(0, (int) TimeUnit.MICROSECONDS.toNanos(20)));
    span1.end();
    // 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, (int) TimeUnit.MICROSECONDS.toNanos(200)));
    span2.end();
    Collection<SpanData> samples = sampleStore.getLatencySampledSpans(LatencyFilter.create(REGISTERED_SPAN_NAME, TimeUnit.MICROSECONDS.toNanos(15), TimeUnit.MICROSECONDS.toNanos(250), 0));
    assertThat(samples).containsExactly(span1.toSpanData(), span2.toSpanData());
}
Also used : SpanData(io.opencensus.trace.export.SpanData) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 17 with RecordEventsSpanImpl

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

the class InProcessRunningSpanStoreImplTest method getSummary_SpansWithDifferentNames.

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

Example 18 with RecordEventsSpanImpl

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

the class InProcessRunningSpanStoreImplTest method getActiveSpans_SpansWithSameName.

@Test
public void getActiveSpans_SpansWithSameName() {
    RecordEventsSpanImpl span1 = createSpan(SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSpan(SPAN_NAME_1);
    RecordEventsSpanImpl span3 = createSpan(SPAN_NAME_1);
    assertThat(activeSpansExporter.getRunningSpans(Filter.create(SPAN_NAME_1, 0))).containsExactly(span1.toSpanData(), span2.toSpanData(), span3.toSpanData());
    assertThat(activeSpansExporter.getRunningSpans(Filter.create(SPAN_NAME_1, 2)).size()).isEqualTo(2);
    assertThat(activeSpansExporter.getRunningSpans(Filter.create(SPAN_NAME_1, 2))).containsAnyOf(span1.toSpanData(), span2.toSpanData(), span3.toSpanData());
    span1.end();
    span2.end();
    span3.end();
}
Also used : RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 19 with RecordEventsSpanImpl

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

the class InProcessRunningSpanStoreImplTest method getActiveSpans_SpansWithDifferentNames.

@Test
public void getActiveSpans_SpansWithDifferentNames() {
    RecordEventsSpanImpl span1 = createSpan(SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSpan(SPAN_NAME_2);
    assertThat(activeSpansExporter.getRunningSpans(Filter.create(SPAN_NAME_1, 0))).containsExactly(span1.toSpanData());
    assertThat(activeSpansExporter.getRunningSpans(Filter.create(SPAN_NAME_1, 2))).containsExactly(span1.toSpanData());
    assertThat(activeSpansExporter.getRunningSpans(Filter.create(SPAN_NAME_2, 0))).containsExactly(span2.toSpanData());
    span1.end();
    span2.end();
}
Also used : RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 20 with RecordEventsSpanImpl

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

the class InProcessRunningSpanStoreImplTest method setMaxNumberOfSpans.

@Test
public void setMaxNumberOfSpans() {
    RecordEventsSpanImpl span1 = createSpan(SPAN_NAME_1);
    RecordEventsSpanImpl span2 = createSpan(SPAN_NAME_2);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(2);
    // This will reset all the spans.
    activeSpansExporter.setMaxNumberOfSpans(10);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(0);
    span1.end();
    span2.end();
    // Add spans again.
    RecordEventsSpanImpl span3 = createSpan(SPAN_NAME_1);
    RecordEventsSpanImpl span4 = createSpan(SPAN_NAME_2);
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(2);
    span3.end();
    span4.end();
    assertThat(activeSpansExporter.getSummary().getPerSpanNameSummary().size()).isEqualTo(0);
}
Also used : 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