zipkin2.Span.annotations()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(146)

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

Span.annotations介绍

[英]Events that explain latency with a timestamp. Unlike log statements, annotations are often short or contain codes: for example "brave.flush". Annotations are sorted ascending by timestamp.
[中]用时间戳解释延迟的事件。与日志语句不同,注释通常很短或包含代码:例如“brave.flush”。注释按时间戳升序排序。

代码示例

代码示例来源:origin: openzipkin/brave

/** Call this to block until a span was reported */
protected Span takeSpan() throws InterruptedException {
 Span result = spans.poll(3, TimeUnit.SECONDS);
 assertThat(result)
   .withFailMessage("Span was not reported")
   .isNotNull();
 assertThat(result.annotations())
   .extracting(Annotation::value)
   .doesNotContain(CONTEXT_LEAK);
 return result;
}

代码示例来源:origin: line/armeria

@Test(timeout = 20000)
public void shouldSubmitSpanWhenRequestIsSampled() throws Exception {
  final SpanCollectingReporter reporter = testServiceInvocation(1.0f);
  // check span name
  final Span span = reporter.spans().take();
  assertThat(span.name()).isEqualTo(TEST_METHOD);
  // check kind
  assertThat(span.kind()).isSameAs(Kind.SERVER);
  // only one span should be submitted
  assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull();
  // check # of annotations (we add wire annotations)
  assertThat(span.annotations()).hasSize(2);
  // check tags
  assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of(
      "http.host", "foo.com",
      "http.method", "POST",
      "http.path", "/hello/trustin",
      "http.status_code", "200",
      "http.url", "none+h2c://foo.com/hello/trustin"));
  // check service name
  assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE);
}

代码示例来源:origin: line/armeria

@Test(timeout = 20000)
public void shouldSubmitSpanWhenSampled() throws Exception {
  final SpanCollectingReporter reporter = new SpanCollectingReporter();
  final Tracing tracing = Tracing.newBuilder()
                  .localServiceName(TEST_SERVICE)
                  .spanReporter(reporter)
                  .sampler(Sampler.create(1.0f))
                  .build();
  testRemoteInvocation(tracing, null);
  // check span name
  final Span span = reporter.spans().take();
  assertThat(span.name()).isEqualTo(TEST_SPAN);
  // check kind
  assertThat(span.kind()).isSameAs(Kind.CLIENT);
  // only one span should be submitted
  assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull();
  // check # of annotations (we add wire annotations)
  assertThat(span.annotations()).hasSize(2);
  // check tags
  assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of(
      "http.host", "foo.com",
      "http.method", "POST",
      "http.path", "/hello/armeria",
      "http.status_code", "200",
      "http.url", "none+h2c://foo.com/hello/armeria"));
  // check service name
  assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE);
  // check remote service name
  assertThat(span.remoteServiceName()).isEqualTo("foo.com");
}

代码示例来源:origin: line/armeria

final long clientWireSendTime = clientFooSpan.annotations().stream()
                       .filter(a -> a.value().equals("ws"))
                       .findFirst().get().timestamp();
final long clientWireReceiveTime = clientFooSpan.annotations().stream()
                        .filter(a -> a.value().equals("wr"))
                        .findFirst().get().timestamp();
final long serverWireSendTime = serviceFooSpan.annotations().stream()
                       .filter(a -> a.value().equals("ws"))
                       .findFirst().get().timestamp();
final long serverWireReceiveTime = serviceFooSpan.annotations().stream()
                         .filter(a -> a.value().equals("wr"))
                         .findFirst().get().timestamp();

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

/** Call this to block until a span was reported */
protected Span takeSpan() throws InterruptedException {
 Span result = spans.poll(3, TimeUnit.SECONDS);
 assertThat(result)
   .withFailMessage("Span was not reported")
   .isNotNull();
 assertThat(result.annotations())
   .extracting(Annotation::value)
   .doesNotContain(CONTEXT_LEAK);
 return result;
}

代码示例来源:origin: io.zipkin.zipkin2/zipkin-storage-cassandra

/**
 * Returns a set of annotation getValues and tags joined on equals, delimited by ░
 *
 * @see QueryRequest#annotationQuery()
 */
static @Nullable String annotationQuery(Span span) {
 if (span.annotations().isEmpty() && span.tags().isEmpty()) return null;
 char delimiter = '░'; // as very unlikely to be in the query
 StringBuilder result = new StringBuilder().append(delimiter);
 for (Annotation a : span.annotations()) {
  if (a.value().length() > LONGEST_VALUE_TO_INDEX) continue;
  result.append(a.value()).append(delimiter);
 }
 for (Map.Entry<String, String> tag : span.tags().entrySet()) {
  if (tag.getValue().length() > LONGEST_VALUE_TO_INDEX) continue;
  result.append(tag.getKey()).append(delimiter); // search is possible by key alone
  result.append(tag.getKey() + "=" + tag.getValue()).append(delimiter);
 }
 return result.length() == 1 ? null : result.toString();
}

代码示例来源:origin: apache/cxf

@Override
  protected boolean matchesSafely(Span item) {
    if (!name.equals(item.name())) {
      return false;
    }
    if (matcher != null) {
      return matcher.matches(item.annotations());
    }
    return true;
  }
});

代码示例来源:origin: io.zipkin.zipkin2/zipkin-storage-cassandra

static long guessTimestamp(Span span) {
 assert 0L == span.timestampAsLong() : "method only for when span has no timestamp";
 for (Annotation annotation : span.annotations()) {
  if (0L < annotation.timestamp()) {
   return annotation.timestamp();
  }
 }
 return 0L; // return a timestamp that won't match a query
}

代码示例来源:origin: io.zipkin.zipkin2/zipkin-storage-cassandra-v1

private static long guessTimestamp(Span span) {
 assert 0L == span.timestampAsLong() : "method only for when span has no timestamp";
 for (Annotation annotation : span.annotations()) {
  if (0L < annotation.timestamp()) return annotation.timestamp();
 }
 return 0L; // return a timestamp that won't match a query
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void reportsSpanOn_ServerSend() throws Exception {
 advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$);
 advanceAndRecord(1, root, Annotation.ServerSend$.MODULE$);
 Span span = spansSent.take();
 assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
 assertThat(span.annotations()).isEmpty();
 assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
 assertThat(span.duration()).isEqualTo(1000);
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void reportsSpanOn_ClientRecv() throws Exception {
 advanceAndRecord(0, root, Annotation.ClientSend$.MODULE$);
 advanceAndRecord(1, root, Annotation.ClientRecv$.MODULE$);
 Span span = spansSent.take();
 assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT);
 assertThat(span.annotations()).isEmpty();
 assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
 assertThat(span.duration()).isEqualTo(1000);
}

代码示例来源:origin: io.zipkin.zipkin2/zipkin-storage-cassandra

Input newInput(zipkin2.Span span, UUID ts_uuid) {
 boolean traceIdHigh = !strictTraceId && span.traceId().length() == 32;
 List<AnnotationUDT> annotations;
 if (!span.annotations().isEmpty()) {
  annotations =
    span.annotations().stream().map(AnnotationUDT::new).collect(Collectors.toList());
 } else {
  annotations = Collections.emptyList();
 }
 String annotation_query = searchEnabled ? CassandraUtil.annotationQuery(span) : null;
 return new AutoValue_InsertSpan_Input(
   ts_uuid,
   traceIdHigh ? span.traceId().substring(0, 16) : null,
   traceIdHigh ? span.traceId().substring(16) : span.traceId(),
   span.parentId(),
   span.id(),
   span.kind() != null ? span.kind().name() : null,
   span.name(),
   span.timestampAsLong(),
   span.durationAsLong(),
   span.localEndpoint() != null ? new EndpointUDT(span.localEndpoint()) : null,
   span.remoteEndpoint() != null ? new EndpointUDT(span.remoteEndpoint()) : null,
   annotations,
   span.tags(),
   annotation_query,
   Boolean.TRUE.equals(span.debug()),
   Boolean.TRUE.equals(span.shared()));
}

代码示例来源:origin: gavlyukovskiy/spring-boot-data-source-decorator

@Test
void testShouldAddSpanForConnection() {
  contextRunner.run(context -> {
    DataSource dataSource = context.getBean(DataSource.class);
    ArrayListSpanReporter spanReporter = context.getBean(ArrayListSpanReporter.class);
    Connection connection = dataSource.getConnection();
    connection.commit();
    connection.rollback();
    connection.close();
    assertThat(spanReporter.getSpans()).hasSize(1);
    Span connectionSpan = spanReporter.getSpans().get(0);
    assertThat(connectionSpan.name()).isEqualTo("jdbc:/test/connection");
    assertThat(connectionSpan.annotations()).extracting("value").contains("commit");
    assertThat(connectionSpan.annotations()).extracting("value").contains("rollback");
  });
}

代码示例来源:origin: gavlyukovskiy/spring-boot-data-source-decorator

@Test
void testShouldAddSpanForConnection() {
  contextRunner.run(context -> {
    DataSource dataSource = context.getBean(DataSource.class);
    ArrayListSpanReporter spanReporter = context.getBean(ArrayListSpanReporter.class);
    Connection connection = dataSource.getConnection();
    connection.commit();
    connection.rollback();
    connection.close();
    assertThat(spanReporter.getSpans()).hasSize(1);
    Span connectionSpan = spanReporter.getSpans().get(0);
    assertThat(connectionSpan.name()).isEqualTo("jdbc:/test/connection");
    assertThat(connectionSpan.annotations()).extracting("value").contains("commit");
    assertThat(connectionSpan.annotations()).extracting("value").contains("rollback");
  });
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void reportsSpanOn_Timeout() throws Exception {
 advanceAndRecord(0, root, Annotation.ClientSend$.MODULE$);
 advanceAndRecord(1, root, new Annotation.Message(TimeoutFilter.TimeoutAnnotation()));
 Span span = spansSent.take();
 assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT);
 assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly(
   "finagle.timeout"
 );
 assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
 assertThat(span.duration()).isEqualTo(1000);
}

代码示例来源:origin: io.zipkin.zipkin2/zipkin

@Override void writeValue(Buffer b, Span value) {
 TRACE_ID.write(b, value.traceId());
 PARENT_ID.write(b, value.parentId());
 ID.write(b, value.id());
 KIND.write(b, toByte(value.kind()));
 NAME.write(b, value.name());
 TIMESTAMP.write(b, value.timestampAsLong());
 DURATION.write(b, value.durationAsLong());
 LOCAL_ENDPOINT.write(b, value.localEndpoint());
 REMOTE_ENDPOINT.write(b, value.remoteEndpoint());
 List<Annotation> annotations = value.annotations();
 int annotationLength = annotations.size();
 for (int i = 0; i < annotationLength; i++) {
  ANNOTATION.write(b, annotations.get(i));
 }
 Map<String, String> tags = value.tags();
 if (!tags.isEmpty()) { // avoid allocating an iterator when empty
  for (Map.Entry<String, String> entry : tags.entrySet()) {
   TAG.write(b, entry);
  }
 }
 SpanField.DEBUG.write(b, Boolean.TRUE.equals(value.debug()));
 SpanField.SHARED.write(b, Boolean.TRUE.equals(value.shared()));
}

代码示例来源:origin: io.zipkin.zipkin2/zipkin

@Override int sizeOfValue(Span span) {
 int sizeOfSpan = TRACE_ID.sizeInBytes(span.traceId());
 sizeOfSpan += PARENT_ID.sizeInBytes(span.parentId());
 sizeOfSpan += ID.sizeInBytes(span.id());
 sizeOfSpan += KIND.sizeInBytes(span.kind() != null ? 1 : 0);
 sizeOfSpan += NAME.sizeInBytes(span.name());
 sizeOfSpan += TIMESTAMP.sizeInBytes(span.timestampAsLong());
 sizeOfSpan += DURATION.sizeInBytes(span.durationAsLong());
 sizeOfSpan += LOCAL_ENDPOINT.sizeInBytes(span.localEndpoint());
 sizeOfSpan += REMOTE_ENDPOINT.sizeInBytes(span.remoteEndpoint());
 List<Annotation> annotations = span.annotations();
 int annotationCount = annotations.size();
 for (int i = 0; i < annotationCount; i++) {
  sizeOfSpan += ANNOTATION.sizeInBytes(annotations.get(i));
 }
 Map<String, String> tags = span.tags();
 int tagCount = tags.size();
 if (tagCount > 0) { // avoid allocating an iterator when empty
  for (Map.Entry<String, String> entry : tags.entrySet()) {
   sizeOfSpan += TAG.sizeInBytes(entry);
  }
 }
 sizeOfSpan += DEBUG.sizeInBytes(Boolean.TRUE.equals(span.debug()));
 sizeOfSpan += SHARED.sizeInBytes(Boolean.TRUE.equals(span.shared()));
 return sizeOfSpan;
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void flushesIncompleteSpans() throws Exception {
 advanceAndRecord(0, root, new Annotation.Rpc("GET"));
 advanceAndRecord(15, root, new Annotation.ServiceName("frontend"));
 advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$);
 // Note: there's no ServerSend() which would complete the span.
 time.advance(recorder.ttl.plus(Duration.fromMilliseconds(1))); // advance timer
 timer.tick(); // invokes a flush
 Span span = spansSent.take();
 assertThat(span.id()).isEqualTo(root.spanId().toString());
 assertThat(span.name()).isEqualTo("get");
 assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
 assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly(
   "finagle.flush"
 );
 assertThat(span.duration()).isNull();
}

代码示例来源:origin: io.netifi.proteus/proteus-tracing-openzipkin

private zipkin2.proto3.Span mapSpan(Span span) {
 zipkin2.proto3.Span.Builder builder =
   zipkin2.proto3.Span.newBuilder().setName(span.name()).setTraceId(span.traceId());
 if (span.parentId() != null) {
  builder.setParentId(span.parentId());
 }
 builder.setId(span.id());
 if (span.kind() != null) {
  builder.setKind(zipkin2.proto3.Span.Kind.valueOf(span.kind().name()));
 }
 builder.setTimestamp(span.timestampAsLong()).setDuration(span.durationAsLong());
 if (span.localEndpoint() != null) {
  builder.setLocalEndpoint(mapEndpoint(span.localEndpoint()));
 }
 if (span.remoteEndpoint() != null) {
  builder.setRemoteEndpoint(mapEndpoint(span.remoteEndpoint()));
 }
 for (Annotation annotation : span.annotations()) {
  builder.addAnnotations(mapAnnotation(annotation));
 }
 builder
   .putAllTags(span.tags())
   .setDebug(span.debug() == null ? false : span.debug())
   .setShared(span.shared() == null ? false : span.shared())
   .putTags("group", group)
   .putTags("destination", destination);
 return builder.build();
}

代码示例来源:origin: io.netifi.proteus/tracing-openzipkin

private zipkin2.proto3.Span mapSpan(Span span) {
 zipkin2.proto3.Span.Builder builder =
   zipkin2.proto3.Span.newBuilder().setName(span.name()).setTraceId(span.traceId());
 if (span.parentId() != null) {
  builder.setParentId(span.parentId());
 }
 builder.setId(span.id());
 if (span.kind() != null) {
  builder.setKind(zipkin2.proto3.Span.Kind.valueOf(span.kind().name()));
 }
 builder.setTimestamp(span.timestampAsLong()).setDuration(span.durationAsLong());
 if (span.localEndpoint() != null) {
  builder.setLocalEndpoint(mapEndpoint(span.localEndpoint()));
 }
 if (span.remoteEndpoint() != null) {
  builder.setRemoteEndpoint(mapEndpoint(span.remoteEndpoint()));
 }
 for (Annotation annotation : span.annotations()) {
  builder.addAnnotations(mapAnnotation(annotation));
 }
 builder
   .putAllTags(span.tags())
   .setDebug(span.debug() == null ? false : span.debug())
   .setShared(span.shared() == null ? false : span.shared())
   .putTags("group", group)
   .putTags("destination", destination);
 return builder.build();
}

相关文章