Search in sources :

Example 1 with Annotation

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

the class StackdriverV2ExporterHandler 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(com.google.devtools.cloudtrace.v2.Span.TimeEvent) Annotation(io.opencensus.trace.Annotation)

Example 2 with Annotation

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

the class JaegerExporterHandler method timedEventsToLogs.

private static List<Log> timedEventsToLogs(final List<SpanData.TimedEvent<Annotation>> annotations, final List<SpanData.TimedEvent<MessageEvent>> messageEvents) {
    final List<Log> logs = Lists.newArrayListWithExpectedSize(annotations.size() + messageEvents.size());
    for (final SpanData.TimedEvent<Annotation> event : annotations) {
        final long timestampsInMicros = timestampToMicros(event.getTimestamp());
        logs.add(new Log(timestampsInMicros, attributesToTags(event.getEvent().getAttributes(), descriptionToTag(event.getEvent().getDescription()))));
    }
    for (final SpanData.TimedEvent<MessageEvent> event : messageEvents) {
        final long timestampsInMicros = timestampToMicros(event.getTimestamp());
        final Tag tagMessageId = new Tag(MESSAGE_EVENT_ID, TagType.LONG).setVLong(event.getEvent().getMessageId());
        final Tag tagCompressedSize = new Tag(MESSAGE_EVENT_COMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getCompressedMessageSize());
        final Tag tagUncompressedSize = new Tag(MESSAGE_EVENT_UNCOMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getUncompressedMessageSize());
        logs.add(new Log(timestampsInMicros, Arrays.asList(event.getEvent().getType() == Type.RECEIVED ? RECEIVED_MESSAGE_EVENT_TAG : SENT_MESSAGE_EVENT_TAG, tagMessageId, tagCompressedSize, tagUncompressedSize)));
    }
    return logs;
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Log(io.jaegertracing.thriftjava.Log) MessageEvent(io.opencensus.trace.MessageEvent) Tag(io.jaegertracing.thriftjava.Tag) Annotation(io.opencensus.trace.Annotation)

Example 3 with Annotation

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

the class CensusSpringAspectTest method handlesException.

@Test
public void handlesException() {
    // When
    Sample sample = (Sample) context.getBean("sample");
    try {
        sample.boom();
    } catch (Exception ignored) {
    // ok
    }
    // Then
    List<SpanData> spanList = handler.waitForExport(1);
    assertThat(spanList).isNotNull();
    assertThat(spanList.size()).isEqualTo(1);
    SpanData spanData = spanList.get(0);
    assertThat(spanData.getName()).isEqualTo("boom");
    assertThat(spanData.getStatus()).isEqualTo(Status.UNKNOWN);
    SpanData.TimedEvents<Annotation> annotations = spanData.getAnnotations();
    assertThat(annotations).isNotNull();
    List<SpanData.TimedEvent<Annotation>> events = annotations.getEvents();
    assertThat(events.size()).isEqualTo(1);
    assertThat(events.get(0).getEvent().getDescription()).isEqualTo("error");
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Annotation(io.opencensus.trace.Annotation) Test(org.junit.Test)

Example 4 with Annotation

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

the class SpanOperationsBenchmark method addAnnotationWithAnnotation.

/**
 * Add an annotation with an annotation.
 */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span addAnnotationWithAnnotation(Data data) {
    Span span = data.annotationSpanAnnotation;
    Annotation annotation = Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, data.attributeMap);
    span.addAnnotation(annotation);
    return span;
}
Also used : Span(io.opencensus.trace.Span) Annotation(io.opencensus.trace.Annotation) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 5 with Annotation

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

the class TracezZPageHandler method emitSingleSpan.

// Emits the internal html for a single {@link SpanData}.
@SuppressWarnings("deprecation")
private static void emitSingleSpan(Formatter formatter, SpanData span) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(TimeUnit.SECONDS.toMillis(span.getStartTimestamp().getSeconds()));
    long microsField = TimeUnit.NANOSECONDS.toMicros(span.getStartTimestamp().getNanos());
    String elapsedSecondsStr = span.getEndTimestamp() != null ? String.format("%13.6f", durationToNanos(span.getEndTimestamp().subtractTimestamp(span.getStartTimestamp())) * 1.0e-9) : String.format("%13s", " ");
    SpanContext spanContext = span.getContext();
    formatter.format("<b>%04d/%02d/%02d-%02d:%02d:%02d.%06d %s     TraceId: <b style=\"color:%s;\">%s</b> " + "SpanId: %s ParentSpanId: %s</b>%n", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), microsField, elapsedSecondsStr, spanContext.getTraceOptions().isSampled() ? SAMPLED_TRACE_ID_COLOR : NOT_SAMPLED_TRACE_ID_COLOR, BaseEncoding.base16().lowerCase().encode(spanContext.getTraceId().getBytes()), BaseEncoding.base16().lowerCase().encode(spanContext.getSpanId().getBytes()), BaseEncoding.base16().lowerCase().encode(span.getParentSpanId() == null ? SpanId.INVALID.getBytes() : span.getParentSpanId().getBytes()));
    int lastEntryDayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
    Timestamp lastTimestampNanos = span.getStartTimestamp();
    TimedEvents<Annotation> annotations = span.getAnnotations();
    TimedEvents<io.opencensus.trace.NetworkEvent> networkEvents = span.getNetworkEvents();
    List<TimedEvent<?>> timedEvents = new ArrayList<TimedEvent<?>>(annotations.getEvents());
    timedEvents.addAll(networkEvents.getEvents());
    Collections.sort(timedEvents, new TimedEventComparator());
    for (TimedEvent<?> event : timedEvents) {
        // Special printing so that durations smaller than one second
        // are left padded with blanks instead of '0' characters.
        // E.g.,
        // Number                  Printout
        // ---------------------------------
        // 0.000534                  .   534
        // 1.000534                 1.000534
        long deltaMicros = TimeUnit.NANOSECONDS.toMicros(durationToNanos(event.getTimestamp().subtractTimestamp(lastTimestampNanos)));
        String deltaString;
        if (deltaMicros >= 1000000) {
            deltaString = String.format("%.6f", (deltaMicros / 1000000.0));
        } else {
            deltaString = String.format(".%6d", deltaMicros);
        }
        calendar.setTimeInMillis(TimeUnit.SECONDS.toMillis(event.getTimestamp().getSeconds()) + TimeUnit.NANOSECONDS.toMillis(event.getTimestamp().getNanos()));
        microsField = TimeUnit.NANOSECONDS.toMicros(event.getTimestamp().getNanos());
        int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
        if (dayOfYear == lastEntryDayOfYear) {
            formatter.format("%11s", "");
        } else {
            formatter.format("%04d/%02d/%02d-", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
            lastEntryDayOfYear = dayOfYear;
        }
        formatter.format("%02d:%02d:%02d.%06d %13s ... %s%n", calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), microsField, deltaString, htmlEscaper().escape(event.getEvent() instanceof Annotation ? renderAnnotation((Annotation) event.getEvent()) : renderNetworkEvents((io.opencensus.trace.NetworkEvent) castNonNull(event.getEvent()))));
        lastTimestampNanos = event.getTimestamp();
    }
    Status status = span.getStatus();
    if (status != null) {
        formatter.format("%44s %s%n", "", htmlEscaper().escape(renderStatus(status)));
    }
    formatter.format("%44s %s%n", "", htmlEscaper().escape(renderAttributes(span.getAttributes().getAttributeMap())));
}
Also used : Status(io.opencensus.trace.Status) SpanContext(io.opencensus.trace.SpanContext) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) TimedEvent(io.opencensus.trace.export.SpanData.TimedEvent) Timestamp(io.opencensus.common.Timestamp) Annotation(io.opencensus.trace.Annotation)

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