Search in sources :

Example 6 with RecordEventsSpanImpl

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

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

the class SpanExporterImplTest method createNotSampledEndedSpan.

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

Example 8 with RecordEventsSpanImpl

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

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

the class InProcessSampledSpanStoreImpl method getErrorSampledSpans.

@Override
public Collection<SpanData> getErrorSampledSpans(ErrorFilter filter) {
    int numSpansToReturn = filter.getMaxSpansToReturn() == 0 ? MAX_PER_SPAN_NAME_SAMPLES : filter.getMaxSpansToReturn();
    List<RecordEventsSpanImpl> spans = Collections.emptyList();
    // the lock.
    synchronized (samples) {
        PerSpanNameSamples perSpanNameSamples = samples.get(filter.getSpanName());
        if (perSpanNameSamples != null) {
            spans = perSpanNameSamples.getErrorSamples(filter.getCanonicalCode(), numSpansToReturn);
        }
    }
    List<SpanData> ret = new ArrayList<SpanData>(spans.size());
    for (RecordEventsSpanImpl span : spans) {
        ret.add(span.toSpanData());
    }
    return Collections.unmodifiableList(ret);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) ArrayList(java.util.ArrayList) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl)

Example 10 with RecordEventsSpanImpl

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

the class InProcessSampledSpanStoreImpl method getLatencySampledSpans.

@Override
public Collection<SpanData> getLatencySampledSpans(LatencyFilter filter) {
    int numSpansToReturn = filter.getMaxSpansToReturn() == 0 ? MAX_PER_SPAN_NAME_SAMPLES : filter.getMaxSpansToReturn();
    List<RecordEventsSpanImpl> spans = Collections.emptyList();
    // the lock.
    synchronized (samples) {
        PerSpanNameSamples perSpanNameSamples = samples.get(filter.getSpanName());
        if (perSpanNameSamples != null) {
            spans = perSpanNameSamples.getLatencySamples(filter.getLatencyLowerNs(), filter.getLatencyUpperNs(), numSpansToReturn);
        }
    }
    List<SpanData> ret = new ArrayList<SpanData>(spans.size());
    for (RecordEventsSpanImpl span : spans) {
        ret.add(span.toSpanData());
    }
    return Collections.unmodifiableList(ret);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) ArrayList(java.util.ArrayList) 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