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());
}
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;
}
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());
}
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);
}
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);
}
Aggregations