io.opencensus.trace.Annotation Java Examples

The following examples show how to use io.opencensus.trace.Annotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecordEventsSpanImpl.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Override
public void addAnnotation(String description, Map<String, AttributeValue> attributes) {
  Preconditions.checkNotNull(description, "description");
  Preconditions.checkNotNull(attributes, "attribute");
  synchronized (this) {
    if (hasBeenEnded) {
      logger.log(Level.FINE, "Calling addAnnotation() on an ended Span.");
      return;
    }
    getInitializedAnnotations()
        .addEvent(
            new EventWithNanoTime<Annotation>(
                clock.nowNanos(),
                Annotation.fromDescriptionAndAttributes(description, attributes)));
  }
}
 
Example #2
Source File: TelemetryUtils.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
public static ParentSpan startExplicitParentSpan(String name) {
  Span span;
  if (enabledExporter) {
    span = tracer.spanBuilderWithExplicitParent(name, null).startSpan();
  } else {
    span = tracer.spanBuilderWithExplicitParent(name, null).setRecordEvents(true).startSpan();
  }

  span.addAnnotation(getBaseAnnotation());
  Annotation vmAnno =
      Annotation.fromDescriptionAndAttributes("java.vm properties", javaAttributeMap);
  span.addAnnotation(vmAnno);
  Annotation osAnno = Annotation.fromDescriptionAndAttributes("os properties", osAttributeMap);
  span.addAnnotation(osAnno);
  return new ParentSpan(span, name);
}
 
Example #3
Source File: TracingProxyTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void testTracingException() {
  final MockSpan span = new MockSpan();

  final Foo delegate = new ThrowingFooImpl();

  final Foo proxy = TracingProxy.instrument(Foo.class, delegate, tracer);

  when(tracer.spanBuilder("ThrowingFooImpl.bar")).thenReturn(spanBuilder);
  when(spanBuilder.startSpan()).thenReturn(span);

  try {
    proxy.bar();
    fail();
  } catch (Exception ignore) {
  }

  verify(tracer).spanBuilder("ThrowingFooImpl.bar");
  verify(spanBuilder).startSpan();
  assertThat(span.ended, is(true));
  assertThat(span.status, is(UNKNOWN));
  assertThat(span.annotations, contains(Annotation.fromDescription("Exception thrown")));
}
 
Example #4
Source File: CensusSpringAspectTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #5
Source File: CensusSpringAspectTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void sqlExecute() throws Exception {
  // When
  String sql = "select 1";
  Sample sample = (Sample) context.getBean("sample");
  sample.execute(sql);

  // Then
  List<SpanData> data = handler.waitForExport(1);
  assertThat(data).isNotNull();
  assertThat(data.size()).isEqualTo(1);
  assertThat(data.get(0).getName()).isEqualTo("execute-4705ea0d"); // sql-{hash of sql statement}

  List<SpanData.TimedEvent<Annotation>> events = data.get(0).getAnnotations().getEvents();
  assertThat(events.size()).isEqualTo(1);
  assertThat(events.get(0).getEvent().getDescription()).isEqualTo(sql);
}
 
Example #6
Source File: CensusSpringAspectTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void sqlUpdate() throws Exception {
  // When
  String sql = "update content set value = 1";
  Sample sample = (Sample) context.getBean("sample");
  sample.executeUpdate(sql);

  // Then
  List<SpanData> data = handler.waitForExport(1);
  assertThat(data).isNotNull();
  assertThat(data.size()).isEqualTo(1);
  assertThat(data.get(0).getName()).isEqualTo("executeUpdate-acaeb423");

  List<SpanData.TimedEvent<Annotation>> events = data.get(0).getAnnotations().getEvents();
  assertThat(events.size()).isEqualTo(1);
  assertThat(events.get(0).getEvent().getDescription()).isEqualTo(sql);
}
 
Example #7
Source File: CensusSpringAspectTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void sqlQuery() throws Exception {
  // When
  String sql = "select 2";
  Sample sample = (Sample) context.getBean("sample");
  sample.executeQuery(sql);

  // Then
  List<SpanData> data = handler.waitForExport(1);
  assertThat(data).isNotNull();
  assertThat(data.size()).isEqualTo(1);
  assertThat(data.get(0).getName()).isEqualTo("executeQuery-4705ea0e");

  SpanData.TimedEvents<Annotation> annotations = data.get(0).getAnnotations();
  List<SpanData.TimedEvent<Annotation>> events = annotations.getEvents();
  assertThat(events.size()).isEqualTo(1);
  assertThat(events.get(0).getEvent().getDescription()).isEqualTo(sql);
}
 
Example #8
Source File: TracezZPageHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static String renderAnnotation(Annotation annotation) {
  StringBuilder stringBuilder = new StringBuilder();
  stringBuilder.append(annotation.getDescription());
  if (!annotation.getAttributes().isEmpty()) {
    stringBuilder.append(" ");
    stringBuilder.append(renderAttributes(annotation.getAttributes()));
  }
  return stringBuilder.toString();
}
 
Example #9
Source File: RecordEventsSpanImpl.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@GuardedBy("this")
private TraceEvents<EventWithNanoTime<Annotation>> getInitializedAnnotations() {
  if (annotations == null) {
    annotations =
        new TraceEvents<EventWithNanoTime<Annotation>>(traceParams.getMaxNumberOfAnnotations());
  }
  return annotations;
}
 
Example #10
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void noEventsRecordedAfterEnd() {
  RecordEventsSpanImpl span =
      RecordEventsSpanImpl.startSpan(
          spanContext,
          SPAN_NAME,
          null,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  span.end();
  // Check that adding trace events after Span#end() does not throw any exception and are not
  // recorded.
  span.putAttributes(attributes);
  span.putAttribute(
      "MySingleStringAttributeKey",
      AttributeValue.stringAttributeValue("MySingleStringAttributeValue"));
  span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
  span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
  span.addNetworkEvent(
      NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build());
  span.addLink(Link.fromSpanContext(spanContext, Link.Type.CHILD_LINKED_SPAN));
  SpanData spanData = span.toSpanData();
  assertThat(spanData.getStartTimestamp()).isEqualTo(timestamp);
  assertThat(spanData.getAttributes().getAttributeMap()).isEmpty();
  assertThat(spanData.getAnnotations().getEvents()).isEmpty();
  assertThat(spanData.getNetworkEvents().getEvents()).isEmpty();
  assertThat(spanData.getLinks().getLinks()).isEmpty();
  assertThat(spanData.getStatus()).isEqualTo(Status.OK);
  assertThat(spanData.getEndTimestamp()).isEqualTo(timestamp);
}
 
Example #11
Source File: RecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #12
Source File: NoRecordEventsSpanImplTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void doNotCrash() {
  Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
  attributes.put(
      "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
  Map<String, AttributeValue> multipleAttributes = new HashMap<String, AttributeValue>();
  multipleAttributes.put(
      "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
  multipleAttributes.put("MyBooleanAttributeKey", AttributeValue.booleanAttributeValue(true));
  multipleAttributes.put("MyLongAttributeKey", AttributeValue.longAttributeValue(123));
  // Tests only that all the methods are not crashing/throwing errors.
  noRecordEventsSpan.putAttribute(
      "MyStringAttributeKey2", AttributeValue.stringAttributeValue("MyStringAttributeValue2"));
  noRecordEventsSpan.addAttributes(attributes);
  noRecordEventsSpan.addAttributes(multipleAttributes);
  noRecordEventsSpan.addAnnotation("MyAnnotation");
  noRecordEventsSpan.addAnnotation("MyAnnotation", attributes);
  noRecordEventsSpan.addAnnotation("MyAnnotation", multipleAttributes);
  noRecordEventsSpan.addAnnotation(Annotation.fromDescription("MyAnnotation"));
  noRecordEventsSpan.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.SENT, 1L).build());
  noRecordEventsSpan.addMessageEvent(MessageEvent.builder(MessageEvent.Type.SENT, 1L).build());
  noRecordEventsSpan.addLink(
      Link.fromSpanContext(SpanContext.INVALID, Link.Type.CHILD_LINKED_SPAN));
  noRecordEventsSpan.setStatus(Status.OK);
  noRecordEventsSpan.end(EndSpanOptions.DEFAULT);
  noRecordEventsSpan.end();
}
 
Example #13
Source File: TelemetryUtils.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
private static Annotation getBaseAnnotation() {
  if (isNull(meghanadaAnnotation)) {
    String version = System.getProperty("meghanada-server.version", "");
    String uid = System.getProperty("meghanada-server.uid", "");
    Map<String, AttributeValue> m = new HashMap<>(2);
    m.put("meghanada-server.version", AttributeValue.stringAttributeValue(version));
    m.put("meghanada-server.uid", AttributeValue.stringAttributeValue(uid));
    meghanadaAnnotation = Annotation.fromDescriptionAndAttributes("meghanada properties", m);
  }
  return meghanadaAnnotation;
}
 
Example #14
Source File: StackdriverV2ExporterHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static Span.TimeEvents toTimeEventsProto(
    TimedEvents<Annotation> annotationTimedEvents,
    TimedEvents<io.opencensus.trace.MessageEvent> messageEventTimedEvents) {
  Span.TimeEvents.Builder timeEventsBuilder = Span.TimeEvents.newBuilder();
  timeEventsBuilder.setDroppedAnnotationsCount(annotationTimedEvents.getDroppedEventsCount());
  for (TimedEvent<Annotation> annotation : annotationTimedEvents.getEvents()) {
    timeEventsBuilder.addTimeEvent(toTimeAnnotationProto(annotation));
  }
  timeEventsBuilder.setDroppedMessageEventsCount(messageEventTimedEvents.getDroppedEventsCount());
  for (TimedEvent<io.opencensus.trace.MessageEvent> networkEvent :
      messageEventTimedEvents.getEvents()) {
    timeEventsBuilder.addTimeEvent(toTimeMessageEventProto(networkEvent));
  }
  return timeEventsBuilder.build();
}
 
Example #15
Source File: StackdriverV2ExporterHandler.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #16
Source File: TraceProtoUtils.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static Span.TimeEvents toTimeEventsProto(
    TimedEvents<Annotation> annotationTimedEvents,
    TimedEvents<io.opencensus.trace.MessageEvent> messageEventTimedEvents) {
  Span.TimeEvents.Builder timeEventsBuilder = Span.TimeEvents.newBuilder();
  timeEventsBuilder.setDroppedAnnotationsCount(annotationTimedEvents.getDroppedEventsCount());
  for (TimedEvent<Annotation> annotation : annotationTimedEvents.getEvents()) {
    timeEventsBuilder.addTimeEvent(toTimeAnnotationProto(annotation));
  }
  timeEventsBuilder.setDroppedMessageEventsCount(messageEventTimedEvents.getDroppedEventsCount());
  for (TimedEvent<io.opencensus.trace.MessageEvent> networkEvent :
      messageEventTimedEvents.getEvents()) {
    timeEventsBuilder.addTimeEvent(toTimeMessageEventProto(networkEvent));
  }
  return timeEventsBuilder.build();
}
 
Example #17
Source File: TraceProtoUtils.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #18
Source File: JaegerExporterHandlerTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void convertErrorSpanDataToJaegerThriftSpan() throws SenderException {
  long startTime = 1519629870001L;
  long endTime = 1519630148002L;
  String statusMessage = "timeout";
  SpanData spanData =
      SpanData.create(
          sampleSpanContext(),
          SpanId.fromBytes(new byte[] {(byte) 0x7F, FF, FF, FF, FF, FF, FF, FF}),
          true,
          "test",
          Kind.SERVER,
          Timestamp.fromMillis(startTime),
          SpanData.Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0),
          SpanData.TimedEvents.create(Collections.<TimedEvent<Annotation>>emptyList(), 0),
          SpanData.TimedEvents.create(Collections.<TimedEvent<MessageEvent>>emptyList(), 0),
          SpanData.Links.create(Collections.<Link>emptyList(), 0),
          0,
          Status.DEADLINE_EXCEEDED.withDescription(statusMessage),
          Timestamp.fromMillis(endTime));

  handler.export(singletonList(spanData));

  verify(mockSender).send(eq(process), captor.capture());
  List<Span> spans = captor.getValue();

  assertThat(spans.size()).isEqualTo(1);
  Span span = spans.get(0);

  assertThat(span.tags.size()).isEqualTo(3);
  assertThat(span.tags)
      .containsExactly(
          new Tag(JaegerExporterHandler.SPAN_KIND, TagType.STRING).setVStr("server"),
          new Tag(JaegerExporterHandler.STATUS_CODE, TagType.LONG).setVLong(4),
          new Tag(JaegerExporterHandler.STATUS_MESSAGE, TagType.STRING).setVStr(statusMessage));
}
 
Example #19
Source File: JaegerExporterHandlerTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static SpanData.TimedEvent<Annotation> sampleAnnotation() {
  return SpanData.TimedEvent.create(
      Timestamp.create(1519629872L, 987654321),
      Annotation.fromDescriptionAndAttributes(
          "annotation #1",
          ImmutableMap.of(
              "bool", AttributeValue.booleanAttributeValue(true),
              "long", AttributeValue.longAttributeValue(1337L),
              "string",
                  AttributeValue.stringAttributeValue(
                      "Kind words do not cost much. Yet they accomplish much. -- Pascal"))));
}
 
Example #20
Source File: RecordEventsSpanImpl.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an immutable representation of all the data from this {@code Span}.
 *
 * @return an immutable representation of all the data from this {@code Span}.
 * @throws IllegalStateException if the Span doesn't have RECORD_EVENTS option.
 */
public SpanData toSpanData() {
  synchronized (this) {
    SpanData.Attributes attributesSpanData =
        attributes == null
            ? SpanData.Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0)
            : SpanData.Attributes.create(attributes, attributes.getNumberOfDroppedAttributes());
    SpanData.TimedEvents<Annotation> annotationsSpanData =
        createTimedEvents(getInitializedAnnotations(), timestampConverter);
    SpanData.TimedEvents<io.opencensus.trace.MessageEvent> messageEventsSpanData =
        createTimedEvents(getInitializedNetworkEvents(), timestampConverter);
    SpanData.Links linksSpanData =
        links == null
            ? SpanData.Links.create(Collections.<Link>emptyList(), 0)
            : SpanData.Links.create(
                new ArrayList<Link>(links.events), links.getNumberOfDroppedEvents());
    return SpanData.create(
        getContext(),
        parentSpanId,
        hasRemoteParent,
        name,
        kind,
        timestampConverter.convertNanoTime(startNanoTime),
        attributesSpanData,
        annotationsSpanData,
        messageEventsSpanData,
        linksSpanData,
        numberOfChildren,
        hasBeenEnded ? getStatusWithDefault() : null,
        hasBeenEnded ? timestampConverter.convertNanoTime(endNanoTime) : null);
  }
}
 
Example #21
Source File: RecordEventsSpanImpl.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
public void addAnnotation(Annotation annotation) {
  Preconditions.checkNotNull(annotation, "annotation");
  synchronized (this) {
    if (hasBeenEnded) {
      logger.log(Level.FINE, "Calling addAnnotation() on an ended Span.");
      return;
    }
    getInitializedAnnotations()
        .addEvent(new EventWithNanoTime<Annotation>(clock.nowNanos(), annotation));
  }
}
 
Example #22
Source File: BasicDataBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** Create an Annotation. */
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Annotation createAnnotation(Data data) {
  return Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, data.attributeMap);
}
 
Example #23
Source File: SpanOperationsBenchmark.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example #24
Source File: SpanDataTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void spanData_AllDataEmpty() {
  SpanData spanData =
      SpanData.create(
          spanContext,
          parentSpanId,
          false,
          SPAN_NAME,
          null,
          startTimestamp,
          Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0),
          TimedEvents.create(Collections.<SpanData.TimedEvent<Annotation>>emptyList(), 0),
          TimedEvents.create(Collections.<SpanData.TimedEvent<MessageEvent>>emptyList(), 0),
          Links.create(Collections.<Link>emptyList(), 0),
          0,
          status,
          endTimestamp);
  assertThat(spanData.getContext()).isEqualTo(spanContext);
  assertThat(spanData.getParentSpanId()).isEqualTo(parentSpanId);
  assertThat(spanData.getHasRemoteParent()).isFalse();
  assertThat(spanData.getName()).isEqualTo(SPAN_NAME);
  assertThat(spanData.getStartTimestamp()).isEqualTo(startTimestamp);
  assertThat(spanData.getAttributes().getAttributeMap().isEmpty()).isTrue();
  assertThat(spanData.getAnnotations().getEvents().isEmpty()).isTrue();
  assertThat(spanData.getNetworkEvents().getEvents().isEmpty()).isTrue();
  assertThat(spanData.getMessageEvents().getEvents().isEmpty()).isTrue();
  assertThat(spanData.getLinks().getLinks().isEmpty()).isTrue();
  assertThat(spanData.getChildSpanCount()).isEqualTo(0);
  assertThat(spanData.getStatus()).isEqualTo(status);
  assertThat(spanData.getEndTimestamp()).isEqualTo(endTimestamp);
}
 
Example #25
Source File: TelemetryUtils.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
public static void setStatusINTERNAL(String message) {
  // add error info annotation
  Span current = tracer.getCurrentSpan();
  current.addAnnotation(getBaseAnnotation());
  HashMap<String, AttributeValue> newMap = new HashMap<>(javaAttributeMap);
  newMap.put("java.vm.memory", AttributeValue.stringAttributeValue(Config.getMemoryString()));
  Annotation vmAnno = Annotation.fromDescriptionAndAttributes("java.vm properties", newMap);
  current.addAnnotation(vmAnno);
  Annotation osAnno = Annotation.fromDescriptionAndAttributes("os properties", osAttributeMap);
  current.addAnnotation(osAnno);
  TelemetryUtils.setStatus(Status.INTERNAL.withDescription(message));
}
 
Example #26
Source File: SpanData.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new immutable {@code SpanData}.
 *
 * @deprecated Use {@link #create(SpanContext, SpanId, Boolean, String, Kind, Timestamp,
 *     Attributes, TimedEvents, TimedEvents, Links, Integer, Status, Timestamp)}.
 */
@Deprecated
public static SpanData create(
    SpanContext context,
    @Nullable SpanId parentSpanId,
    @Nullable Boolean hasRemoteParent,
    String name,
    Timestamp startTimestamp,
    Attributes attributes,
    TimedEvents<Annotation> annotations,
    TimedEvents<? extends io.opencensus.trace.BaseMessageEvent> messageOrNetworkEvents,
    Links links,
    @Nullable Integer childSpanCount,
    @Nullable Status status,
    @Nullable Timestamp endTimestamp) {
  return create(
      context,
      parentSpanId,
      hasRemoteParent,
      name,
      null,
      startTimestamp,
      attributes,
      annotations,
      messageOrNetworkEvents,
      links,
      childSpanCount,
      status,
      endTimestamp);
}
 
Example #27
Source File: StatsTestUtils.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public void addAnnotation(Annotation annotation) {}
 
Example #28
Source File: ZipkinExporterHandler.java    From opencensus-java with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #29
Source File: StatsTestUtils.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public void addAnnotation(Annotation annotation) {}
 
Example #30
Source File: TelemetryUtils.java    From meghanada-server with GNU General Public License v3.0 4 votes vote down vote up
private static void addAnnotaion(Annotation annotation) {
  Span current = tracer.getCurrentSpan();
  current.addAnnotation(annotation);
}