Search in sources :

Example 81 with SpanData

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());
}
Also used : SpanData(io.opencensus.trace.export.SpanData) RecordEventsSpanImpl(io.opencensus.implcore.trace.RecordEventsSpanImpl) Test(org.junit.Test)

Example 82 with SpanData

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();
}
Also used : SpanData(io.opencensus.trace.export.SpanData) NetworkEvent(io.opencensus.trace.NetworkEvent) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 83 with SpanData

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);
    }
}
Also used : SpanData(io.opencensus.trace.export.SpanData) TraceParams(io.opencensus.trace.config.TraceParams) Annotation(io.opencensus.trace.Annotation) Test(org.junit.Test)

Example 84 with SpanData

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());
}
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 85 with SpanData

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

Aggregations

SpanData (io.opencensus.trace.export.SpanData)86 Test (org.junit.Test)74 RecordEventsSpanImpl (io.opencensus.implcore.trace.RecordEventsSpanImpl)18 Link (io.opencensus.trace.Link)17 AttributeValue (io.opencensus.trace.AttributeValue)13 Collectors (java.util.stream.Collectors)13 Scope (org.apache.ignite.spi.tracing.Scope)13 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)13 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)13 TracingSpi (org.apache.ignite.spi.tracing.TracingSpi)13 IgniteEx (org.apache.ignite.internal.IgniteEx)12 SAMPLING_RATE_ALWAYS (org.apache.ignite.spi.tracing.TracingConfigurationParameters.SAMPLING_RATE_ALWAYS)12 OpenCensusTracingSpi (org.apache.ignite.spi.tracing.opencensus.OpenCensusTracingSpi)12 SpanId (io.opencensus.trace.SpanId)11 Collections (java.util.Collections)9 SpanType (org.apache.ignite.internal.processors.tracing.SpanType)9 TX (org.apache.ignite.spi.tracing.Scope.TX)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8 Set (java.util.Set)8