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