Search in sources :

Example 6 with Annotation

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();
}
Also used : TimeEvent(io.opencensus.proto.trace.v1.Span.TimeEvent) Annotation(io.opencensus.trace.Annotation)

Example 7 with Annotation

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();
}
Also used : Status(io.opencensus.trace.Status) AttributeValue(io.opencensus.trace.AttributeValue) SpanContext(io.opencensus.trace.SpanContext) Span(zipkin2.Span) Annotation(io.opencensus.trace.Annotation) Map(java.util.Map)

Example 8 with Annotation

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

Aggregations

Annotation (io.opencensus.trace.Annotation)8 SpanData (io.opencensus.trace.export.SpanData)3 SpanContext (io.opencensus.trace.SpanContext)2 Status (io.opencensus.trace.Status)2 Test (org.junit.Test)2 TimeEvent (com.google.devtools.cloudtrace.v2.Span.TimeEvent)1 Log (io.jaegertracing.thriftjava.Log)1 Tag (io.jaegertracing.thriftjava.Tag)1 Timestamp (io.opencensus.common.Timestamp)1 TimeEvent (io.opencensus.proto.trace.v1.Span.TimeEvent)1 AttributeValue (io.opencensus.trace.AttributeValue)1 MessageEvent (io.opencensus.trace.MessageEvent)1 Span (io.opencensus.trace.Span)1 TraceParams (io.opencensus.trace.config.TraceParams)1 TimedEvent (io.opencensus.trace.export.SpanData.TimedEvent)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 BenchmarkMode (org.openjdk.jmh.annotations.BenchmarkMode)1