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

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

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

Span.parentId介绍

[英]The parent's #id or null if this the root span in a trace.

This is the same encoding as #id. For example ffdc9bb9a6453df3
[中]父级的#id或null(如果这是跟踪中的根跨度)。
这与#id的编码相同。例如ffdc9bb9a6453df3

代码示例

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

assertThat(serviceFooSpan.parentId()).isNull();
assertThat(clientBarSpan.parentId()).isEqualTo(serviceFooSpan.id());
assertThat(serviceBarSpan.parentId()).isEqualTo(serviceFooSpan.id());
assertThat(clientQuxSpan.parentId()).isEqualTo(serviceBarSpan.id());
assertThat(serviceQuxSpan.parentId()).isEqualTo(serviceBarSpan.id());

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

assertThat(clientFooSpan.parentId()).isNull();
assertThat(serviceFooSpan.parentId()).isNull();
assertThat(clientBarSpan.parentId()).isEqualTo(clientFooSpan.id());
assertThat(serviceBarSpan.parentId()).isEqualTo(clientFooSpan.id());
assertThat(clientQuxSpan.parentId()).isEqualTo(clientBarSpan.id());
assertThat(serviceQuxSpan.parentId()).isEqualTo(clientBarSpan.id());

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

@JsonGetter("parent_id")
public long getParentId() {
  if (delegateSpan.parentId() == null) {
    return 0;
  } else {
    return lowerHexToUnsignedLong(delegateSpan.parentId());
  }
}

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

@Test
public void usesExistingTraceId() 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("X-B3-TraceId", traceId)
   .header("X-B3-ParentSpanId", parentId)
   .header("X-B3-SpanId", spanId)
   .header("X-B3-Sampled", "1")
   .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.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.brave/brave-http-tests

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create a local 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.
 */
private void createsChildSpan(String path) {
 Request request = new Request.Builder().url(url(path)).build();
 try (Response response = client.newCall(request).execute()) {
  if (response.code() == 404) throw new AssumptionViolatedException(path + " not supported");
 } catch (AssumptionViolatedException e) {
  throw e;
 } catch (Exception e) {
  // ok, but the span should include an error!
 }
 List<Span> trace = collectedSpans();
 assertThat(trace).hasSize(2);
 Span child = trace.get(0);
 Span parent = trace.get(1);
 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: io.smartup.zipkin/zipkin-datadog-reporter-core

@Override
public void report(Span span) {
  if (flushingThread == null) {
    synchronized (this) {
      if (flushingThread == null) {
        running.set(true);
        flushingThread = new Thread(() -> flushPeriodically(), "zipkin-datadog-flusher");
        flushingThread.setDaemon(true);
        flushingThread.start();
      }
    }
  }
  PendingTrace trace = new PendingTrace();
  PendingTrace previousTrace = pendingTraces.putIfAbsent(span.traceId(), trace);
  trace = previousTrace != null ? previousTrace : trace; // Handles race condition
  trace.spans.add(new DDMappingSpan(span));
  /* If the span kind is server or consumer, we assume it is the root of the trace.
   * That implies all span children have likely already been reported and can be
   * flushed in the next cycle, though in some async cases, this might not be the case.
   */
  if (span.kind() == Span.Kind.SERVER
      || span.kind() == Span.Kind.CONSUMER
      || span.parentId() == null) {
    trace.expiration = nanoTime() + COMPLETION_DELAY;
  } else {
    trace.expiration = nanoTime() + TIMEOUT_DELAY;
  }
}

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

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

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvided() {
  final Response r = createWebClient("/bookstore/books", braveClientProvider).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
  assertThatTraceHeadersArePresent(r, false);
}

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

@Test
public void testThatNewInnerSpanIsCreatedUsingAsyncInvocation() {
  final SpanId spanId = fromRandom();
  final Response r = withTrace(createWebClient("/bookstore/books/async"), spanId).get();
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(2));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books/async"));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("processing books"));
  assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
  assertThat(TestSpanReporter.getAllSpans().get(0).parentId(),
    equalTo(TestSpanReporter.getAllSpans().get(1).id()));
  assertThatTraceIsPresent(r, spanId);
}

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

@Test
public void testThatNewChildSpanIsCreatedWhenParentIsProvided() throws MalformedURLException {
  final Tracing brave = Tracing.newBuilder()
    .localServiceName("book-store")
    .spanReporter(new TestSpanReporter())
    .build();
  final BookStoreService service = createJaxWsService(new Configurator() {
    @Override
    public void configure(final JaxWsProxyFactoryBean factory) {
      factory.getFeatures().add(new BraveClientFeature(brave));
    }
  });
  assertThat(service.getBooks().size(), equalTo(2));
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("post /bookstore"));
  assertThat(TestSpanReporter.getAllSpans().get(2).name(),
    equalTo("post http://localhost:" + PORT + "/bookstore"));
  final Map<String, List<String>> response = getResponseHeaders(service);
  assertThatTraceHeadersArePresent(response, false);
}

代码示例来源:origin: Nike-Inc/wingtips

@UseDataProvider("idSanitizationScenarios")
@Test
public void convertWingtipsSpanToZipkinSpan_sanitizes_parentSpanId_as_expected_when_sanitization_is_enabled(
  IdSanitizationScenario scenario
) {
  // given
  impl = new WingtipsToZipkinSpanConverterDefaultImpl(true);
  final Endpoint zipkinEndpoint = Endpoint.newBuilder().serviceName(UUID.randomUUID().toString()).build();
  final Span wingtipsSpan = Span.newBuilder("foo", SpanPurpose.CLIENT)
                 .withParentSpanId(scenario.originalId)
                 .withSpanStartTimeEpochMicros(Math.abs(random.nextLong()))
                 .withDurationNanos(Math.abs(random.nextLong()))
                 .build();
  // when
  zipkin2.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint);
  // then
  assertThat(zipkinSpan.parentId()).isEqualTo(scenario.expectedSanitizedResultForSpanIdOrParentSpanId);
  assertThat(zipkinSpan.tags().get("invalid.parent_id")).isEqualTo(scenario.originalId);
}

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

@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  final Span span = brave.tracer().nextSpan().name("test span").start();
  try {
    try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
      final Response r = client.get();
      assertEquals(Status.OK.getStatusCode(), r.getStatus());
      assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
      assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
      assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
      assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
      assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
      assertThatTraceHeadersArePresent(r, true);
    }
  } finally {
    span.finish();
  }
  // Await till flush happens, usually a second is enough
  await().atMost(Duration.ONE_SECOND).until(()-> TestSpanReporter.getAllSpans().size() == 4);
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
  assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}

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

相关文章