io.opencensus.trace.Annotation类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中io.opencensus.trace.Annotation类的一些代码示例,展示了Annotation类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation类的具体详情如下:
包路径:io.opencensus.trace.Annotation
类名称:Annotation

Annotation介绍

[英]A text annotation with a set of attributes.
[中]

代码示例

代码示例来源:origin: googleapis/google-cloud-java

private Annotation sessionAnnotation(Session session) {
 AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName());
 return Annotation.fromDescriptionAndAttributes(
   "Using Session", ImmutableMap.of("sessionId", sessionId));
}

代码示例来源:origin: census-instrumentation/opencensus-java

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

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromDescriptionAndAttributes_EmptyAttributes() {
 Annotation annotation =
   Annotation.fromDescriptionAndAttributes(
     "MyAnnotationText", Collections.<String, AttributeValue>emptyMap());
 assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText");
 assertThat(annotation.getAttributes().size()).isEqualTo(0);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromDescription() {
 Annotation annotation = Annotation.fromDescription("MyAnnotationText");
 assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText");
 assertThat(annotation.getAttributes().size()).isEqualTo(0);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void annotation_ToString() {
  Annotation annotation = Annotation.fromDescription("MyAnnotationText");
  assertThat(annotation.toString()).contains("MyAnnotationText");
  Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
  attributes.put(
    "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
  annotation = Annotation.fromDescriptionAndAttributes("MyAnnotationText2", attributes);
  assertThat(annotation.toString()).contains("MyAnnotationText2");
  assertThat(annotation.toString()).contains(attributes.toString());
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@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);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test(expected = NullPointerException.class)
public void fromDescription_NullDescription() {
 Annotation.fromDescription(null);
}

代码示例来源:origin: census-instrumentation/opencensus-java

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

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromDescriptionAndAttributes() {
 Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
 attributes.put(
   "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
 Annotation annotation = Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes);
 assertThat(annotation.getDescription()).isEqualTo("MyAnnotationText");
 assertThat(annotation.getAttributes()).isEqualTo(attributes);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void annotation_EqualsAndHashCode() {
 EqualsTester tester = new EqualsTester();
 Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
 attributes.put(
   "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
 tester
   .addEqualityGroup(
     Annotation.fromDescription("MyAnnotationText"),
     Annotation.fromDescriptionAndAttributes(
       "MyAnnotationText", Collections.<String, AttributeValue>emptyMap()))
   .addEqualityGroup(
     Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes),
     Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes))
   .addEqualityGroup(Annotation.fromDescription("MyAnnotationText2"));
 tester.testEquals();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@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);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@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.
 BlankSpan.INSTANCE.putAttribute(
   "MyStringAttributeKey2", AttributeValue.stringAttributeValue("MyStringAttributeValue2"));
 BlankSpan.INSTANCE.addAttributes(attributes);
 BlankSpan.INSTANCE.addAttributes(multipleAttributes);
 BlankSpan.INSTANCE.addAnnotation("MyAnnotation");
 BlankSpan.INSTANCE.addAnnotation("MyAnnotation", attributes);
 BlankSpan.INSTANCE.addAnnotation("MyAnnotation", multipleAttributes);
 BlankSpan.INSTANCE.addAnnotation(Annotation.fromDescription("MyAnnotation"));
 BlankSpan.INSTANCE.addNetworkEvent(NetworkEvent.builder(NetworkEvent.Type.SENT, 1L).build());
 BlankSpan.INSTANCE.addMessageEvent(MessageEvent.builder(MessageEvent.Type.SENT, 1L).build());
 BlankSpan.INSTANCE.addLink(
   Link.fromSpanContext(SpanContext.INVALID, Link.Type.CHILD_LINKED_SPAN));
 BlankSpan.INSTANCE.setStatus(Status.OK);
 BlankSpan.INSTANCE.end(EndSpanOptions.DEFAULT);
 BlankSpan.INSTANCE.end();
}

代码示例来源:origin: census-instrumentation/opencensus-java

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

代码示例来源:origin: com.google.cloud/google-cloud-spanner

private Annotation sessionAnnotation(Session session) {
 AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName());
 return Annotation.fromDescriptionAndAttributes(
   "Using Session", ImmutableMap.of("sessionId", sessionId));
}

代码示例来源:origin: census-instrumentation/opencensus-java

span.putAttributes(attributes);
testClock.advanceTime(Duration.create(0, 100));
span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
testClock.advanceTime(Duration.create(0, 100));
span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
  .isEqualTo(timestamp.addNanos(100));
assertThat(spanData.getAnnotations().getEvents().get(0).getEvent())
  .isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp())
  .isEqualTo(timestamp.addNanos(200));
assertThat(spanData.getAnnotations().getEvents().get(1).getEvent())
  .isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes));
assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0);
assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);

代码示例来源:origin: census-instrumentation/opencensus-java

@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);
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

timestampConverter,
    testClock);
Annotation annotation = Annotation.fromDescription(ANNOTATION_DESCRIPTION);
for (int i = 0; i < 2 * maxNumberOfAnnotations; i++) {
 span.addAnnotation(annotation);

代码示例来源:origin: io.opencensus/opencensus-exporter-trace-stackdriver

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

代码示例来源:origin: census-instrumentation/opencensus-java

@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)));
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

span.putAttributes(attributes);
testClock.advanceTime(Duration.create(0, 100));
span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
testClock.advanceTime(Duration.create(0, 100));
span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
  .isEqualTo(timestamp.addNanos(100));
assertThat(spanData.getAnnotations().getEvents().get(0).getEvent())
  .isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp())
  .isEqualTo(timestamp.addNanos(200));
assertThat(spanData.getAnnotations().getEvents().get(1).getEvent())
  .isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes));
assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0);
assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);

相关文章