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

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

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

TraceContext.traceIdString介绍

[英]Returns the hex representation of the span's trace ID
[中]返回跨度跟踪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: spring-cloud/spring-cloud-sleuth

String traceIdString = currentSpan.traceIdString();
MDC.put("traceId", traceIdString);
MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);

代码示例来源:origin: spring-cloud/spring-cloud-sleuth

String traceIdString = currentSpan.traceIdString();
MDC.put("traceId", traceIdString);
MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);

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

@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

RecordedRequest request = server.takeRequest();
assertThat(request.getHeader("x-b3-traceId"))
  .isEqualTo(parent.context().traceIdString());
assertThat(request.getHeader("x-b3-parentspanid"))
  .isEqualTo(parent.context().spanIdString());

代码示例来源:origin: societe-generale/rabbitmq-advanced-spring-boot-starter

@Override
public Message postProcessMessage(final Message message) {
 MessageProperties messageProperties = message.getMessageProperties();
 String correlationId = messageProperties.getCorrelationId();
 if (correlationId == null) {
  correlationId = (tracer!=null && tracer.currentSpan()!=null)?
      tracer.currentSpan().context().traceIdString():UUID.randomUUID().toString();
  messageProperties.setCorrelationId(correlationId);
 }
 messageProperties.getHeaders().put("correlation-id", correlationId);
 return message;
}

代码示例来源: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: org.apache.camel/camel-zipkin

private void serverResponse(Tracing brave, String serviceName, Exchange exchange) {
  Span span = null;
  ZipkinState state = exchange.getProperty(ZipkinState.KEY, ZipkinState.class);
  if (state != null) {
    // only process if it was a zipkin server event
    span = state.popServerSpan();
  }
  if (span != null) {
    ZipkinServerResponseAdapter parser = new ZipkinServerResponseAdapter(this, exchange);
    parser.onResponse(exchange, span.customizer());
    span.finish();
    TraceContext context = span.context();
    String traceId = "" + context.traceIdString();
    String spanId = "" + context.spanId();
    String parentId = context.parentId() != null ? "" + context.parentId() : null;
    if (camelContext.isUseMDCLogging()) {
      MDC.put("traceId", traceId);
      MDC.put("spanId", spanId);
      MDC.put("parentId", parentId);
    }
    if (LOG.isDebugEnabled()) {
      if (parentId != null) {
        LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
      } else {
        LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
      }
    }
  }
}

代码示例来源:origin: org.apache.camel/camel-zipkin

private void clientResponse(Tracing brave, String serviceName, ExchangeSentEvent event) {
  Span span = null;
  ZipkinState state = event.getExchange().getProperty(ZipkinState.KEY, ZipkinState.class);
  if (state != null) {
    // only process if it was a zipkin client event
    span = state.popClientSpan();
  }
  if (span != null) {
    ZipkinClientResponseAdaptor parser = new ZipkinClientResponseAdaptor(this, event.getEndpoint());
    parser.onResponse(event.getExchange(), span.customizer());
    span.finish();
    TraceContext context = span.context();
    String traceId = "" + context.traceIdString();
    String spanId = "" + context.spanId();
    String parentId = context.parentId() != null ? "" + context.parentId() : null;
    if (camelContext.isUseMDCLogging()) {
      MDC.put("traceId", traceId);
      MDC.put("spanId", spanId);
      MDC.put("parentId", parentId);
    }
    if (LOG.isDebugEnabled()) {
      if (parentId != null) {
        LOG.debug(String.format("clientResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
      } else {
        LOG.debug(String.format("clientResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
      }
    }
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-sleuth-core

String traceIdString = currentSpan.traceIdString();
MDC.put("traceId", traceIdString);
MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);

代码示例来源:origin: org.springframework.cloud/spring-cloud-sleuth-core

String traceIdString = currentSpan.traceIdString();
MDC.put("traceId", traceIdString);
MDC.put(LEGACY_TRACE_ID_NAME, traceIdString);

代码示例来源: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: com.github.gitssie/play-transport

public void propagationTraceInfo(HttpUriRequest request, Span span) {
  TraceContext currentSpan = span.context();
  request.addHeader("X-B3-TraceId",currentSpan.traceIdString());
  request.addHeader("X-B3-SpanId", HexCodec.toLowerHex(currentSpan.spanId()));
  if(currentSpan.parentId() != null) {
    request.addHeader("X-B3-ParentSpanId", HexCodec.toLowerHex(currentSpan.parentId()));
  }
  request.addHeader("X-B3-Sampled",String.valueOf(currentSpan.sampled()));
}

代码示例来源:origin: org.apache.camel/camel-zipkin

String traceId = "" + context.traceIdString();
String spanId = "" + context.spanId();
String parentId = context.parentId() != null ? "" + context.parentId() : null;

代码示例来源: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: org.apache.camel/camel-zipkin

String traceId = "" + context.traceIdString();
String spanId = "" + context.spanId();
String parentId = context.parentId() != null ? "" + context.parentId() : null;

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

RecordedRequest request = server.takeRequest();
assertThat(request.getHeader("x-b3-traceId"))
  .isEqualTo(parent.context().traceIdString());
assertThat(request.getHeader("x-b3-parentspanid"))
  .isEqualTo(parent.context().spanIdString());

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

相关文章