use of io.opencensus.trace.Annotation in project instrumentation-java by census-instrumentation.
the class TraceProtoUtils method toTimeAnnotationProto.
private static TimeEvent toTimeAnnotationProto(TimedEvent<Annotation> timedEvent) {
TimeEvent.Builder timeEventBuilder = TimeEvent.newBuilder().setTime(toTimestampProto(timedEvent.getTimestamp()));
Annotation annotation = timedEvent.getEvent();
timeEventBuilder.setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(toTruncatableStringProto(annotation.getDescription())).setAttributes(toAttributesBuilderProto(annotation.getAttributes(), 0)).build());
return timeEventBuilder.build();
}
use of io.opencensus.trace.Annotation in project instrumentation-java by census-instrumentation.
the class ZipkinExporterHandler method generateSpan.
@SuppressWarnings("deprecation")
static Span generateSpan(SpanData spanData, Endpoint localEndpoint) {
SpanContext context = spanData.getContext();
long startTimestamp = toEpochMicros(spanData.getStartTimestamp());
// TODO(sebright): Fix the Checker Framework warning.
@SuppressWarnings("nullness") long endTimestamp = toEpochMicros(spanData.getEndTimestamp());
// TODO(bdrutu): Fix the Checker Framework warning.
@SuppressWarnings("nullness") Span.Builder spanBuilder = Span.newBuilder().traceId(context.getTraceId().toLowerBase16()).id(context.getSpanId().toLowerBase16()).kind(toSpanKind(spanData)).name(spanData.getName()).timestamp(toEpochMicros(spanData.getStartTimestamp())).duration(endTimestamp - startTimestamp).localEndpoint(localEndpoint);
if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
spanBuilder.parentId(spanData.getParentSpanId().toLowerBase16());
}
for (Map.Entry<String, AttributeValue> label : spanData.getAttributes().getAttributeMap().entrySet()) {
spanBuilder.putTag(label.getKey(), attributeValueToString(label.getValue()));
}
Status status = spanData.getStatus();
if (status != null) {
spanBuilder.putTag(STATUS_CODE, status.getCanonicalCode().toString());
if (status.getDescription() != null) {
spanBuilder.putTag(STATUS_DESCRIPTION, status.getDescription());
}
if (!status.isOk()) {
spanBuilder.putTag(STATUS_ERROR, status.getCanonicalCode().toString());
}
}
for (TimedEvent<Annotation> annotation : spanData.getAnnotations().getEvents()) {
spanBuilder.addAnnotation(toEpochMicros(annotation.getTimestamp()), annotation.getEvent().getDescription());
}
for (TimedEvent<io.opencensus.trace.MessageEvent> messageEvent : spanData.getMessageEvents().getEvents()) {
spanBuilder.addAnnotation(toEpochMicros(messageEvent.getTimestamp()), messageEvent.getEvent().getType().name());
}
return spanBuilder.build();
}
use of io.opencensus.trace.Annotation 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);
}
}
Aggregations