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

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

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

Span.timestampAsLong介绍

[英]Like #timestamp() except returns a primitive where zero implies absent.

Using this method will avoid allocation, so is encouraged when copying data.
[中]与#timestamp()类似,但返回一个原语,其中零表示不存在。
使用此方法将避免分配,因此在复制数据时鼓励使用此方法。

代码示例

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

protected Tracing.Builder tracingBuilder(Sampler sampler) {
  return Tracing.newBuilder()
    .spanReporter(s -> {
     // make sure the context was cleared prior to finish.. no leaks!
     TraceContext current = httpTracing.tracing().currentTraceContext().get();
     boolean contextLeak = false;
     if (current != null) {
      // add annotation in addition to throwing, in case we are off the main thread
      if (current.spanIdString().equals(s.id())) {
       s = s.toBuilder().addAnnotation(s.timestampAsLong(), CONTEXT_LEAK).build();
       contextLeak = true;
      }
     }
     spans.add(s);
     // throw so that we can see the path to the code that leaked the context
     if (contextLeak) {
      throw new AssertionError(CONTEXT_LEAK + " on " + Thread.currentThread().getName());
     }
    })
    .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, EXTRA_KEY))
    .currentTraceContext(currentTraceContext)
    .sampler(sampler);
 }
}

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

final long clientStartTime = clientFooSpan.timestampAsLong();
final long clientWireSendTime = clientFooSpan.annotations().stream()
                       .filter(a -> a.value().equals("ws"))
final long clientEndTime = clientStartTime + clientFooSpan.durationAsLong();
final long serverStartTime = serviceFooSpan.timestampAsLong();
final long serverWireSendTime = serviceFooSpan.annotations().stream()
                       .filter(a -> a.value().equals("ws"))

代码示例来源:origin: io.smartup.zipkin/zipkin-datadog-reporter-core

@JsonGetter("start")
public long getStartTime() {
  return TimeUnit.MICROSECONDS.toNanos(delegateSpan.timestampAsLong());
}

代码示例来源:origin: io.zipkin.dependencies/zipkin-dependencies-cassandra3

@Override
 public Iterable<DependencyLink> call(Iterable<Span> spans) {
  if (logInitializer != null) logInitializer.run();
  List<Span> sameTraceId = new ArrayList<>();
  for (Span span : spans) {
   // check to see if the trace is within the interval
   if (span.parentId() == null) {
    long timestamp = span.timestampAsLong();
    if (timestamp == 0 || timestamp < startTs || timestamp > endTs) {
     return Collections.emptyList();
    }
   }
   sameTraceId.add(span);
  }
  return new DependencyLinker().putTrace(sameTraceId).link();
 }
}

代码示例来源: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: io.zipkin.zipkin2/zipkin-storage-cassandra-v1

V1Span span = converter.convert(v2);
long ts_micro = v2.timestampAsLong();
if (ts_micro == 0L) ts_micro = guessTimestamp(v2);

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

@Override
 public Iterable<DependencyLink> call(Iterable<CassandraRow> rows) {
  if (logInitializer != null) logInitializer.run();
  V1ThriftSpanReader reader = V1ThriftSpanReader.create();
  V1SpanConverter converter = V1SpanConverter.create();
  List<Span> sameTraceId = new ArrayList<>();
  for (CassandraRow row : rows) {
   try {
    V1Span v1Span = reader.read(row.getBytes("span"));
    for (Span span : converter.convert(v1Span)) {
     // check to see if the trace is within the interval
     if (span.parentId() == null) {
      long timestamp = span.timestampAsLong();
      if (timestamp == 0 || timestamp < startTs || timestamp > endTs) {
       return Collections.emptyList();
      }
     }
     sameTraceId.add(span);
    }
   } catch (RuntimeException e) {
    log.warn(
      String.format(
        "Unable to decode span from traces where trace_id=%s and ts=%s and span_name='%s'",
        row.getLong("trace_id"), row.getDate("ts").getTime(), row.getString("span_name")),
      e);
   }
  }
  return new DependencyLinker().putTrace(sameTraceId).link();
 }
}

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

long ts_micro = s.timestampAsLong();
if (ts_micro == 0L) ts_micro = guessTimestamp(s);

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

protected Tracing.Builder tracingBuilder(Sampler sampler) {
  return Tracing.newBuilder()
    .spanReporter(s -> {
     // make sure the context was cleared prior to finish.. no leaks!
     TraceContext current = httpTracing.tracing().currentTraceContext().get();
     boolean contextLeak = false;
     if (current != null) {
      // add annotation in addition to throwing, in case we are off the main thread
      if (current.spanIdString().equals(s.id())) {
       s = s.toBuilder().addAnnotation(s.timestampAsLong(), CONTEXT_LEAK).build();
       contextLeak = true;
      }
     }
     spans.add(s);
     // throw so that we can see the path to the code that leaked the context
     if (contextLeak) {
      throw new AssertionError(CONTEXT_LEAK + " on " + Thread.currentThread().getName());
     }
    })
    .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, EXTRA_KEY))
    .currentTraceContext(currentTraceContext)
    .sampler(sampler);
 }
}

代码示例来源: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: io.zipkin.zipkin2/zipkin

@Override
public synchronized Call<Void> accept(List<Span> spans) {
 int delta = spans.size();
 int spansToRecover = (spansByTraceIdTimeStamp.size() + delta) - maxSpanCount;
 evictToRecoverSpans(spansToRecover);
 for (Span span : spans) {
  long timestamp = span.timestampAsLong();
  String lowTraceId = lowTraceId(span.traceId());
  TraceIdTimestamp traceIdTimeStamp = new TraceIdTimestamp(lowTraceId, timestamp);
  spansByTraceIdTimeStamp.put(traceIdTimeStamp, span);
  traceIdToTraceIdTimeStamps.put(lowTraceId, traceIdTimeStamp);
  acceptedSpanCount++;
  if (!searchEnabled) continue;
  String spanName = span.name();
  if (span.localServiceName() != null) {
   serviceToTraceIds.put(span.localServiceName(), lowTraceId);
   if (spanName != null) serviceToSpanNames.put(span.localServiceName(), spanName);
  }
  if (span.remoteServiceName() != null) {
   serviceToTraceIds.put(span.remoteServiceName(), lowTraceId);
   if (spanName != null) serviceToSpanNames.put(span.remoteServiceName(), spanName);
  }
  for (Map.Entry<String, String> tag : span.tags().entrySet()) {
   if (autocompleteKeys.contains(tag.getKey())) {
    autocompleteTags.put(tag.getKey(), tag.getValue());
   }
  }
 }
 return Call.create(null /* Void == null */);
}

代码示例来源: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: 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

result.timestamp(value.timestampAsLong());
result.duration(value.durationAsLong());

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

toTruncatableString(zipkinSpan.name() != null ? zipkinSpan.name() : ""));
if (zipkinSpan.timestampAsLong() != 0L) {
 spanBuilder.setStartTime(createTimestamp(zipkinSpan.timestampAsLong()));
 if (zipkinSpan.durationAsLong() != 0L) {
  Timestamp endTime =
    createTimestamp(zipkinSpan.timestampAsLong() + zipkinSpan.durationAsLong());
  spanBuilder.setEndTime(endTime);

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

b.writeAscii(",\"name\":\"").writeUtf8(jsonEscape(value.name())).writeByte('"');
if (value.timestampAsLong() != 0L) {
 b.writeAscii(",\"timestamp\":").writeAscii(value.timestampAsLong());

代码示例来源: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();
}

代码示例来源: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: netifi-proteus/proteus-java

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

相关文章