Search in sources :

Example 6 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class RecordEventsSpanImplTest method deprecatedAddAttributesStillWorks.

@Test
public void deprecatedAddAttributesStillWorks() {
    RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, TraceParams.DEFAULT, startEndHandler, timestampConverter, testClock);
    span.addAttributes(attributes);
    span.end();
    SpanData spanData = span.toSpanData();
    assertThat(spanData.getAttributes().getAttributeMap()).isEqualTo(attributes);
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Test(org.junit.Test)

Example 7 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class RecordEventsSpanImplTest method droppingAttributes.

@Test
public void droppingAttributes() {
    final int maxNumberOfAttributes = 8;
    TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
    RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
    for (int i = 0; i < 2 * maxNumberOfAttributes; i++) {
        Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
        attributes.put("MyStringAttributeKey" + i, AttributeValue.longAttributeValue(i));
        span.putAttributes(attributes);
    }
    SpanData spanData = span.toSpanData();
    assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(maxNumberOfAttributes);
    assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
    for (int i = 0; i < maxNumberOfAttributes; i++) {
        assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + (i + maxNumberOfAttributes))).isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
    }
    span.end();
    spanData = span.toSpanData();
    assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(maxNumberOfAttributes);
    assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
    for (int i = 0; i < maxNumberOfAttributes; i++) {
        assertThat(spanData.getAttributes().getAttributeMap().get("MyStringAttributeKey" + (i + maxNumberOfAttributes))).isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
    }
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) HashMap(java.util.HashMap) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Example 8 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class RecordEventsSpanImplTest method droppingNetworkEvents.

@Test
public void droppingNetworkEvents() {
    final int maxNumberOfNetworkEvents = 8;
    TraceParams traceParams = TraceParams.DEFAULT.toBuilder().setMaxNumberOfNetworkEvents(maxNumberOfNetworkEvents).build();
    RecordEventsSpanImpl span = RecordEventsSpanImpl.startSpan(spanContext, SPAN_NAME, null, parentSpanId, false, traceParams, startEndHandler, timestampConverter, testClock);
    NetworkEvent networkEvent = NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build();
    for (int i = 0; i < 2 * maxNumberOfNetworkEvents; i++) {
        span.addNetworkEvent(networkEvent);
        testClock.advanceTime(Duration.create(0, 100));
    }
    SpanData spanData = span.toSpanData();
    assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(maxNumberOfNetworkEvents);
    assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(maxNumberOfNetworkEvents);
    for (int i = 0; i < maxNumberOfNetworkEvents; i++) {
        assertThat(spanData.getNetworkEvents().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfNetworkEvents + i)));
        assertThat(spanData.getNetworkEvents().getEvents().get(i).getEvent()).isEqualTo(networkEvent);
    }
    span.end();
    spanData = span.toSpanData();
    assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(maxNumberOfNetworkEvents);
    assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(maxNumberOfNetworkEvents);
    for (int i = 0; i < maxNumberOfNetworkEvents; i++) {
        assertThat(spanData.getNetworkEvents().getEvents().get(i).getTimestamp()).isEqualTo(timestamp.addNanos(100L * (maxNumberOfNetworkEvents + i)));
        assertThat(spanData.getNetworkEvents().getEvents().get(i).getEvent()).isEqualTo(networkEvent);
    }
}
Also used : SpanData(io.opencensus.trace.export.SpanData) NetworkEvent(io.opencensus.trace.NetworkEvent) TraceParams(io.opencensus.trace.config.TraceParams) Test(org.junit.Test)

Example 9 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class SpanBuilderImplTest method startRemoteSpan_NullParent.

@Test
public void startRemoteSpan_NullParent() {
    RecordEventsSpanImpl span = (RecordEventsSpanImpl) SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, null, spanBuilderOptions).setRecordEvents(true).startSpan();
    assertThat(span.getContext().isValid()).isTrue();
    assertThat(span.getOptions().contains(Options.RECORD_EVENTS)).isTrue();
    assertThat(span.getContext().getTraceOptions().isSampled()).isTrue();
    SpanData spanData = span.toSpanData();
    assertThat(spanData.getParentSpanId()).isNull();
    assertThat(spanData.getHasRemoteParent()).isNull();
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Test(org.junit.Test)

Example 10 with SpanData

use of io.opencensus.trace.export.SpanData in project instrumentation-java by census-instrumentation.

the class SpanBuilderImplTest method startRemoteSpan.

@Test
public void startRemoteSpan() {
    SpanContext spanContext = SpanContext.create(TraceId.generateRandomId(randomHandler.current()), SpanId.generateRandomId(randomHandler.current()), TraceOptions.DEFAULT);
    RecordEventsSpanImpl span = (RecordEventsSpanImpl) SpanBuilderImpl.createWithRemoteParent(SPAN_NAME, spanContext, spanBuilderOptions).setRecordEvents(true).startSpan();
    assertThat(span.getContext().isValid()).isTrue();
    assertThat(span.getContext().getTraceId()).isEqualTo(spanContext.getTraceId());
    assertThat(span.getContext().getTraceOptions().isSampled()).isTrue();
    SpanData spanData = span.toSpanData();
    assertThat(spanData.getParentSpanId()).isEqualTo(spanContext.getSpanId());
    assertThat(spanData.getHasRemoteParent()).isTrue();
}
Also used : SpanContext(io.opencensus.trace.SpanContext) SpanData(io.opencensus.trace.export.SpanData) 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