brave.propagation.TraceContext.spanIdString()方法的使用及代码示例

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

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

TraceContext.spanIdString介绍

[英]Returns the hex representation of the span's ID
[中]

代码示例

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

/**
 * Idempotently sets correlation properties to hex representation of trace identifiers in this
 * context.
 */
void maybeReplaceTraceContext(
  TraceContext currentSpan,
  String previousTraceId,
  @Nullable String previousParentId,
  String previousSpanId
) {
 String traceId = currentSpan.traceIdString();
 if (!traceId.equals(previousTraceId)) put("traceId", currentSpan.traceIdString());
 String parentId = currentSpan.parentIdString();
 if (parentId == null) {
  remove("parentId");
 } else {
  boolean sameParentId = parentId.equals(previousParentId);
  if (!sameParentId) put("parentId", parentId);
 }
 String spanId = currentSpan.spanIdString();
 if (!spanId.equals(previousSpanId)) put("spanId", spanId);
}

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

@Test public void makesChildOfCurrentSpan() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 RecordedRequest request = server.takeRequest();
 assertThat(request.getHeader("x-b3-traceId"))
   .isEqualTo(parent.context().traceIdString());
 assertThat(request.getHeader("x-b3-parentspanid"))
   .isEqualTo(parent.context().spanIdString());
 assertThat(Arrays.asList(takeSpan(), takeSpan()))
   .extracting(Span::kind)
   .containsOnly(null, Span.Kind.CLIENT);
}

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

@Override public boolean handle(TraceContext context, MutableSpan span) {
 if (!Boolean.TRUE.equals(context.sampled())) return true;
 Span.Builder builderWithContextData = Span.newBuilder()
   .traceId(context.traceIdString())
   .parentId(context.parentIdString())
   .id(context.spanIdString());
 if (context.debug()) builderWithContextData.debug(true);
 converter.convert(span, builderWithContextData);
 spanReporter.report(builderWithContextData.build());
 return true;
}

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

@Override public void inject(TraceContext traceContext, C carrier) {
  setter.put(carrier, propagation.traceIdKey, traceContext.traceIdString());
  setter.put(carrier, propagation.spanIdKey, traceContext.spanIdString());
  String parentId = traceContext.parentIdString();
  if (parentId != null) {
   setter.put(carrier, propagation.parentSpanIdKey, parentId);
  }
  if (traceContext.debug()) {
   setter.put(carrier, propagation.debugKey, "1");
  } else if (traceContext.sampled() != null) {
   setter.put(carrier, propagation.sampledKey, traceContext.sampled() ? "1" : "0");
  }
 }
}

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

.isEqualTo(parent.context().traceIdString());
assertThat(request.getHeader("x-b3-parentspanid"))
  .isEqualTo(parent.context().spanIdString());

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

/**
 * Idempotently sets correlation properties to hex representation of trace identifiers in this
 * context.
 */
void maybeReplaceTraceContext(
  TraceContext currentSpan,
  String previousTraceId,
  @Nullable String previousParentId,
  String previousSpanId
) {
 String traceId = currentSpan.traceIdString();
 if (!traceId.equals(previousTraceId)) put("traceId", currentSpan.traceIdString());
 String parentId = currentSpan.parentIdString();
 if (parentId == null) {
  remove("parentId");
 } else {
  boolean sameParentId = parentId.equals(previousParentId);
  if (!sameParentId) put("parentId", parentId);
 }
 String spanId = currentSpan.spanIdString();
 if (!spanId.equals(previousSpanId)) put("spanId", spanId);
}

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

@Test public void makesChildOfCurrentSpan() throws Exception {
 Tracer tracer = httpTracing.tracing().tracer();
 server.enqueue(new MockResponse());
 ScopedSpan parent = tracer.startScopedSpan("test");
 try {
  get(client, "/foo");
 } finally {
  parent.finish();
 }
 RecordedRequest request = server.takeRequest();
 assertThat(request.getHeader("x-b3-traceId"))
   .isEqualTo(parent.context().traceIdString());
 assertThat(request.getHeader("x-b3-parentspanid"))
   .isEqualTo(parent.context().spanIdString());
 assertThat(Arrays.asList(takeSpan(), takeSpan()))
   .extracting(Span::kind)
   .containsOnly(null, Span.Kind.CLIENT);
}

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

@Override public boolean handle(TraceContext context, MutableSpan span) {
 if (!Boolean.TRUE.equals(context.sampled())) return true;
 Span.Builder builderWithContextData = Span.newBuilder()
   .traceId(context.traceIdString())
   .parentId(context.parentIdString())
   .id(context.spanIdString());
 if (context.debug()) builderWithContextData.debug(true);
 converter.convert(span, builderWithContextData);
 spanReporter.report(builderWithContextData.build());
 return true;
}

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

@Override public void inject(TraceContext traceContext, C carrier) {
  setter.put(carrier, propagation.traceIdKey, traceContext.traceIdString());
  setter.put(carrier, propagation.spanIdKey, traceContext.spanIdString());
  String parentId = traceContext.parentIdString();
  if (parentId != null) {
   setter.put(carrier, propagation.parentSpanIdKey, parentId);
  }
  if (traceContext.debug()) {
   setter.put(carrier, propagation.debugKey, "1");
  } else if (traceContext.sampled() != null) {
   setter.put(carrier, propagation.sampledKey, traceContext.sampled() ? "1" : "0");
  }
 }
}

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

.isEqualTo(parent.context().traceIdString());
assertThat(request.getHeader("x-b3-parentspanid"))
  .isEqualTo(parent.context().spanIdString());

相关文章