use of io.opencensus.trace.export.SpanData 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());
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class RecordEventsSpanImplTest method toSpanData_ActiveSpan.
@Test
public void toSpanData_ActiveSpan() {
RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, true, TraceParams.DEFAULT, startEndHandler, timestampConverter, testClock);
Mockito.verify(startEndHandler, Mockito.times(1)).onStart(span);
span.putAttribute("MySingleStringAttributeKey", AttributeValue.stringAttributeValue("MySingleStringAttributeValue"));
span.putAttributes(attributes);
testClock.advanceTime(Duration.create(0, 100));
span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
testClock.advanceTime(Duration.create(0, 100));
span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
testClock.advanceTime(Duration.create(0, 100));
NetworkEvent networkEvent = NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build();
span.addNetworkEvent(networkEvent);
testClock.advanceTime(Duration.create(0, 100));
Link link = Link.fromSpanContext(spanContext, Link.Type.CHILD_LINKED_SPAN);
span.addLink(link);
SpanData spanData = span.toSpanData();
assertThat(spanData.getContext()).isEqualTo(spanContext);
assertThat(spanData.getName()).isEqualTo(SPAN_NAME);
assertThat(spanData.getParentSpanId()).isEqualTo(parentSpanId);
assertThat(spanData.getHasRemoteParent()).isTrue();
assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(0);
assertThat(spanData.getAttributes().getAttributeMap()).isEqualTo(expectedAttributes);
assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(0);
assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(2);
assertThat(spanData.getAnnotations().getEvents().get(0).getTimestamp()).isEqualTo(timestamp.addNanos(100));
assertThat(spanData.getAnnotations().getEvents().get(0).getEvent()).isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp()).isEqualTo(timestamp.addNanos(200));
assertThat(spanData.getAnnotations().getEvents().get(1).getEvent()).isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes));
assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0);
assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);
assertThat(spanData.getNetworkEvents().getEvents().get(0).getTimestamp()).isEqualTo(timestamp.addNanos(300));
assertThat(spanData.getNetworkEvents().getEvents().get(0).getEvent()).isEqualTo(networkEvent);
assertThat(spanData.getLinks().getDroppedLinksCount()).isEqualTo(0);
assertThat(spanData.getLinks().getLinks().size()).isEqualTo(1);
assertThat(spanData.getLinks().getLinks().get(0)).isEqualTo(link);
assertThat(spanData.getStartTimestamp()).isEqualTo(timestamp);
assertThat(spanData.getStatus()).isNull();
assertThat(spanData.getEndTimestamp()).isNull();
}
use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.
the class RecordEventsSpanImplTest method droppingAnnotations.
@Test
public void droppingAnnotations() {
final int maxNumberOfAnnotations = 8;
TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfAnnotations(maxNumberOfAnnotations).build();
RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
Annotation annotation = Annotation.fromDescription(ANNOTATION_DESCRIPTION);
for (int i = 0; i < 2 * maxNumberOfAnnotations; i++) {
span.addAnnotation(annotation);
testClock.advanceTime(Duration.create(0, 100));
}
SpanData spanData = span.toSpanData();
assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(maxNumberOfAnnotations);
assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(maxNumberOfAnnotations);
for (int i = 0; i < maxNumberOfAnnotations; i++) {
assertThat(spanData.getAnnotations().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfAnnotations + i)));
assertThat(spanData.getAnnotations().getEvents().get(i).getEvent()).isEqualTo(annotation);
}
span.end();
spanData = span.toSpanData();
assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(maxNumberOfAnnotations);
assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(maxNumberOfAnnotations);
for (int i = 0; i < maxNumberOfAnnotations; i++) {
assertThat(spanData.getAnnotations().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfAnnotations + i)));
assertThat(spanData.getAnnotations().getEvents().get(i).getEvent()).isEqualTo(annotation);
}
}
use of io.opencensus.trace.export.SpanData 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());
}
use of io.opencensus.trace.export.SpanData 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());
}
Aggregations