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

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

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

Span.traceId介绍

[英]Trace identifier, set on all spans within it.

Encoded as 16 or 32 lowercase hex characters corresponding to 64 or 128 bits. For example, a 128bit trace ID looks like 4e441824ec2b6a44ffdc9bb9a6453df3.

Some systems downgrade trace identifiers to 64bit by dropping the left-most 16 characters. For example, 4e441824ec2b6a44ffdc9bb9a6453df3 becomes ffdc9bb9a6453df3.
[中]跟踪标识符,设置在其中的所有跨距上。
编码为16或32个小写十六进制字符,对应于64或128位。例如,128位跟踪ID看起来像4E44824EC2B6A44FFDC9BB9A6453DF3。
一些系统通过删除最左边的16个字符将跟踪标识符降级为64位。例如,4E44824EC2B6A44FFDC9BB9A6453DF3变为ffdc9bb9a6453df3。

代码示例

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

@Test
public void readsExtra_existingTrace() throws Exception {
 String traceId = "463ac35c9f6413ad";
 readsExtra(new Request.Builder()
   .header("X-B3-TraceId", traceId)
   .header("X-B3-SpanId", traceId));
 Span span = takeSpan();
 assertThat(span.traceId()).isEqualTo(traceId);
 assertThat(span.id()).isEqualTo(traceId);
}

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

@Test
public void usesExistingTraceId() throws Exception {
 String path = "/foo";
 final String traceId = "463ac35c9f6413ad";
 final String parentId = traceId;
 final String spanId = "48485a3953bb6124";
 get(new Request.Builder().url(url(path))
   .header("X-B3-TraceId", traceId)
   .header("X-B3-ParentSpanId", parentId)
   .header("X-B3-SpanId", spanId)
   .header("X-B3-Sampled", "1")
   .build());
 Span span = takeSpan();
 assertThat(span.traceId()).isEqualTo(traceId);
 assertThat(span.parentId()).isEqualTo(parentId);
 assertThat(span.id()).isEqualTo(spanId);
}

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

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create an in-process span. When this works, it should be a child of the
 * "current span", in this case the span representing an incoming server request. When thread
 * state isn't managed properly, the child span will appear as a new trace.
 */
@Test
public void createsChildSpan() throws Exception {
 get("/child");
 Span child = takeSpan();
 Span parent = takeSpan();
 assertThat(parent.traceId()).isEqualTo(child.traceId());
 assertThat(parent.id()).isEqualTo(child.parentId());
 assertThat(parent.timestamp()).isLessThan(child.timestamp());
 assertThat(parent.duration()).isGreaterThan(child.duration());
}

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

@Test(timeout = 10000)
public void testServiceHasMultipleClientRequests() throws Exception {
  assertThat(zipClient.hello("Lee")).isEqualTo("Hello, Lee!, and Hello, Lee!");
  final Span[] spans = spanReporter.take(6);
  final String traceId = spans[0].traceId();
  assertThat(spans).allMatch(s -> s.traceId().equals(traceId));
}

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

final String traceId = spans[0].traceId();
assertThat(spans).allMatch(s -> s.traceId().equals(traceId));

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

final String traceId = spans[0].traceId();
assertThat(spans).allMatch(s -> s.traceId().equals(traceId));

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

@Override public String call(Span span) throws Exception {
 return span.traceId();
}

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

@Override
public List<Span> map(List<Span> input) {
 Iterator<Span> i = input.iterator();
 while (i.hasNext()) { // Not using removeIf as that's java 8+
  Span next = i.next();
  if (!next.traceId().equals(traceId)) i.remove();
 }
 return input;
}

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

static Collection<List<Span>> strictByTraceId(List<Span> next) {
 Map<String, List<Span>> groupedByTraceId = new LinkedHashMap<>();
 for (Span span : next) {
  String traceId = span.traceId();
  if (!groupedByTraceId.containsKey(traceId)) {
   groupedByTraceId.put(traceId, new ArrayList<>());
  }
  groupedByTraceId.get(traceId).add(span);
 }
 return groupedByTraceId.values();
}

代码示例来源:origin: com.google.cloud.trace.adapters.zipkin/translation

@Override
 public int compare(Span o1, Span o2) {
  int result = o1.traceId().compareTo(o2.traceId());
  if (result != 0) return result;
  return o1.id().compareTo(o2.id());
 }
});

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

@Override public List<List<Span>> map(List<Span> input) {
 if (input.isEmpty()) return Collections.emptyList();
 Map<String, List<Span>> groupedByTraceId = new LinkedHashMap<>();
 for (Span span : input) {
  String traceId = span.traceId();
  if (!strictTraceId) traceId = lowerTraceId(traceId);
  if (!groupedByTraceId.containsKey(traceId)) {
   groupedByTraceId.put(traceId, new ArrayList<>());
  }
  groupedByTraceId.get(traceId).add(span);
 }
 return new ArrayList<>(groupedByTraceId.values());
}

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

String idString(Span span) {
 return span.traceId() + "/" + span.id();
}

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

List<Span> sample(List<Span> input) {
 List<Span> sampled = new ArrayList<>(input.size());
 for (int i = 0, length = input.size(); i < length; i++) {
  Span s = input.get(i);
  if (sampler.isSampled(s.traceId(), Boolean.TRUE.equals(s.debug()))) {
   sampled.add(s);
  }
 }
 int dropped = input.size() - sampled.size();
 if (dropped > 0) metrics.incrementSpansDropped(dropped);
 return sampled;
}

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

@Test
public void readsExtra_existingTrace() throws Exception {
 String traceId = "463ac35c9f6413ad";
 readsExtra(new Request.Builder()
   .header("X-B3-TraceId", traceId)
   .header("X-B3-SpanId", traceId));
 Span span = takeSpan();
 assertThat(span.traceId()).isEqualTo(traceId);
 assertThat(span.id()).isEqualTo(traceId);
}

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

/**
 * This method only returns the lower 64 bits of the trace id, so that is all that will be sent to Datadog.
 *
 * @return
 */
@JsonGetter("trace_id")
public long getTraceId() {
  return lowerHexToUnsignedLong(delegateSpan.traceId());
}

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

@Test
public void usesExistingTraceId_b3() throws Exception {
 String path = "/foo";
 final String traceId = "463ac35c9f6413ad";
 final String parentId = traceId;
 final String spanId = "48485a3953bb6124";
 Request request = new Request.Builder().url(url(path))
   .header("b3", traceId + "-" + spanId + "-1-" + parentId)
   .build();
 try (Response response = client.newCall(request).execute()) {
  assertThat(response.isSuccessful()).isTrue();
 }
 assertThat(collectedSpans()).allSatisfy(s -> {
  assertThat(s.traceId()).isEqualTo(traceId);
  assertThat(s.parentId()).isEqualTo(parentId);
  assertThat(s.id()).isEqualTo(spanId);
 });
}

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

@Test
public void usesExistingTraceId() throws Exception {
 String path = "/foo";
 final String traceId = "463ac35c9f6413ad";
 final String parentId = traceId;
 final String spanId = "48485a3953bb6124";
 get(new Request.Builder().url(url(path))
   .header("X-B3-TraceId", traceId)
   .header("X-B3-ParentSpanId", parentId)
   .header("X-B3-SpanId", spanId)
   .header("X-B3-Sampled", "1")
   .build());
 Span span = takeSpan();
 assertThat(span.traceId()).isEqualTo(traceId);
 assertThat(span.parentId()).isEqualTo(parentId);
 assertThat(span.id()).isEqualTo(spanId);
}

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

@Override
public synchronized Call<List<Span>> getTrace(String traceId) {
 traceId = Span.normalizeTraceId(traceId);
 List<Span> spans = spansByTraceId(lowTraceId(traceId));
 if (spans == null || spans.isEmpty()) return Call.emptyList();
 if (!strictTraceId) return Call.create(spans);
 List<Span> filtered = new ArrayList<>(spans);
 Iterator<Span> iterator = filtered.iterator();
 while (iterator.hasNext()) {
  if (!iterator.next().traceId().equals(traceId)) {
   iterator.remove();
  }
 }
 return Call.create(filtered);
}

代码示例来源:origin: io.github.jeqo.zipkin/zipkin-storage-kafka

static Call<Void> create(Producer<String, byte[]> producer, String spansTopic, Span span) {
 byte[] encodedSpan = SpanBytesEncoder.PROTO3.encode(span);
 StoreSpanCall call = new StoreSpanCall(producer, spansTopic, span.traceId(), encodedSpan);
 return call.handleError(call);
}

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

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create an in-process span. When this works, it should be a child of the
 * "current span", in this case the span representing an incoming server request. When thread
 * state isn't managed properly, the child span will appear as a new trace.
 */
@Test
public void createsChildSpan() throws Exception {
 get("/child");
 Span child = takeSpan();
 Span parent = takeSpan();
 assertThat(parent.traceId()).isEqualTo(child.traceId());
 assertThat(parent.id()).isEqualTo(child.parentId());
 assertThat(parent.timestamp()).isLessThan(child.timestamp());
 assertThat(parent.duration()).isGreaterThan(child.duration());
}

相关文章