brave.Tracer.newChild()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(86)

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

Tracer.newChild介绍

[英]Explicitly creates a child within an existing trace. The result will be have its parent ID set to the input's span ID. If a sampling decision has not yet been made, one will happen here.

To implicitly create a new trace, or a span within an existing one, use #nextSpan().
[中]在现有跟踪中显式创建子级。结果将其父ID设置为输入的span ID。如果尚未做出采样决定,将在此处进行。
要隐式创建新跟踪,或在现有跟踪中创建范围,请使用#nextSpan()。

代码示例

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

/**
 * Returns a new child span if there's a {@link #currentSpan()} or a new trace if there isn't.
 *
 * <p>Prefer {@link #startScopedSpan(String)} if you are tracing a synchronous function or code
 * block.
 */
public Span nextSpan() {
 TraceContext parent = currentTraceContext.get();
 return parent != null ? newChild(parent) : newTrace();
}

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

void newChildWithSpanInScope(Tracer tracer, TraceContext context) {
 Span span = tracer.newChild(context).name("encode").start();
 try (Tracer.SpanInScope scope = tracer.withSpanInScope(span)) {
  span.tag("foo", "bar");
  span.tag("baz", "qux");
 } finally {
  span.finish();
 }
}

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

/**
 * MethodInterceptor for {@link SimpleMessageListenerContainer.ContainerDelegate#invokeListener(Channel,
 * Message)}
 */
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable {
 Message message = (Message) methodInvocation.getArguments()[1];
 TraceContextOrSamplingFlags extracted = springRabbitTracing.extractAndClearHeaders(message);
 // named for BlockingQueueConsumer.nextMessage, which we can't currently see
 Span consumerSpan = tracer.nextSpan(extracted);
 Span listenerSpan = tracer.newChild(consumerSpan.context());
 if (!consumerSpan.isNoop()) {
  setConsumerSpan(consumerSpan, message.getMessageProperties());
  // incur timestamp overhead only once
  long timestamp = tracing.clock(consumerSpan.context()).currentTimeMicroseconds();
  consumerSpan.start(timestamp);
  long consumerFinish = timestamp + 1L; // save a clock reading
  consumerSpan.finish(consumerFinish);
  // not using scoped span as we want to start with a pre-configured time
  listenerSpan.name("on-message").start(consumerFinish);
 }
 try (SpanInScope ws = tracer.withSpanInScope(listenerSpan)) {
  return methodInvocation.proceed();
 } catch (Throwable t) {
  listenerSpan.error(t);
  throw t;
 } finally {
  listenerSpan.finish();
 }
}

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

if (!supportsJoin) return newChild(context);
int flags = InternalPropagation.instance.flags(context);
if (alwaysSampleLocal && (flags & FLAG_SAMPLED_LOCAL) != FLAG_SAMPLED_LOCAL) {

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

Span createAndStartProducerSpan(Destination destination, M message) {
 TraceContext maybeParent = current.get();
 // Unlike message consumers, we try current span before trying extraction. This is the proper
 // order because the span in scope should take precedence over a potentially stale header entry.
 //
 // NOTE: Brave instrumentation used properly does not result in stale header entries, as we
 // always clear message headers after reading.
 Span span;
 if (maybeParent == null) {
  span = tracer.nextSpan(extractAndClearMessage(message));
 } else {
  // As JMS is sensitive about write access to headers, we  defensively clear even if it seems
  // upstream would have cleared (because there is a span in scope!).
  span = tracer.newChild(maybeParent);
  clearPropagationHeaders(message);
 }
 if (!span.isNoop()) {
  span.kind(Span.Kind.PRODUCER).name("send");
  if (destination == null) destination = destination(message);
  if (destination != null) jmsTracing.tagQueueOrTopic(destination, span);
  if (remoteServiceName != null) span.remoteServiceName(remoteServiceName);
  span.start();
 }
 addB3SingleHeader(message, span.context());
 return span;
}

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

} else {
 span = tracer.newChild(maybeParent);

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

@Override public Message postProcessMessage(Message message) {
  TraceContext maybeParent = currentTraceContext.get();
  // Unlike message consumers, we try current span before trying extraction. This is the proper
  // order because the span in scope should take precedence over a potentially stale header entry.
  //
  // NOTE: Brave instrumentation used properly does not result in stale header entries, as we
  // always clear message headers after reading.
  Span span;
  if (maybeParent == null) {
   span = tracer.nextSpan(springRabbitTracing.extractAndClearHeaders(message));
  } else {
   // If we have a span in scope assume headers were cleared before
   span = tracer.newChild(maybeParent);
  }

  if (!span.isNoop()) {
   span.kind(Span.Kind.PRODUCER).name("publish");
   if (remoteServiceName != null) span.remoteServiceName(remoteServiceName);
   // incur timestamp overhead only once
   long timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
   span.start(timestamp).finish(timestamp);
  }

  injector.inject(span.context(), message.getMessageProperties());
  return message;
 }
}

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

Span startMessageListenerSpan(Message message) {
  if (!addConsumerSpan) return jmsTracing.nextSpan(message).name("on-message").start();
  TraceContextOrSamplingFlags extracted = jmsTracing.extractAndClearMessage(message);

  // JMS has no visibility of the incoming message, which incidentally could be local!
  Span consumerSpan = tracer.nextSpan(extracted).kind(CONSUMER).name("receive");
  Span listenerSpan = tracer.newChild(consumerSpan.context());

  if (!consumerSpan.isNoop()) {
   long timestamp = tracing.clock(consumerSpan.context()).currentTimeMicroseconds();
   consumerSpan.start(timestamp);
   if (remoteServiceName != null) consumerSpan.remoteServiceName(remoteServiceName);
   jmsTracing.tagQueueOrTopic(message, consumerSpan);
   long consumerFinish = timestamp + 1L; // save a clock reading
   consumerSpan.finish(consumerFinish);

   // not using scoped span as we want to start late
   listenerSpan.name("on-message").start(consumerFinish);
  }
  return listenerSpan;
 }
}

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

if (extracted == null) throw new NullPointerException("extracted == null");
TraceContext context = extracted.context();
if (context != null) return newChild(context);

代码示例来源:origin: apache/servicecomb-java-chassis

private Span createSpan(String spanName, String path) {
 Span currentSpan = tracer.currentSpan();
 if (currentSpan != null) {
  return tracer.newChild(currentSpan.context()).name(spanName).tag(CALL_PATH, path).start();
 }
 return tracer.newTrace().name(spanName).tag(CALL_PATH, path).start();
}

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

/**
 * Returns a new child span if there's a {@link #currentSpan()} or a new trace if there isn't.
 *
 * <p>Prefer {@link #startScopedSpan(String)} if you are tracing a synchronous function or code
 * block.
 */
public Span nextSpan() {
 TraceContext parent = currentTraceContext.get();
 return parent != null ? newChild(parent) : newTrace();
}

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

@Override Span nextSpan(@Nullable SpanId maybeParent) {
 brave.Span span = maybeParent != null
   ? tracer.newChild(toTraceContext(maybeParent))
   : tracer.newTrace();
 return Brave.toSpan(toSpanId(span.context()));
}

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

private TraceScope newOrChildSpan(final String description, final Span parent) {
    if (parent == null) { 
      return new TraceScope(brave, tracer.newTrace().name(description).start());
    }
    return new TraceScope(brave, tracer.newChild(parent.context()).name(description).start());
  }
}

代码示例来源:origin: org.apache.cxf/cxf-integration-tracing-brave

private TraceScope newOrChildSpan(final String description, final Span parent) {
    if (parent == null) { 
      return new TraceScope(brave, tracer.newTrace().name(description).start());
    }
    return new TraceScope(brave, tracer.newChild(parent.context()).name(description).start());
  }
}

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

Span span;
if (last != null) {
  span = brave.tracer().newChild(last.context());
} else {
  span = brave.tracer().nextSpan();

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

private Span createSpan(String spanName, String path) {
 Span currentSpan = tracer.currentSpan();
 if (currentSpan != null) {
  return tracer.newChild(currentSpan.context()).name(spanName).tag(CALL_PATH, path).start();
 }
 return tracer.newTrace().name(spanName).tag(CALL_PATH, path).start();
}

代码示例来源:origin: io.servicecomb/tracing-zipkin

private Span createSpan(String spanName, String path) {
 Span currentSpan = tracer.currentSpan();
 if (currentSpan != null) {
  return tracer.newChild(currentSpan.context()).name(spanName).tag(CALL_PATH, path).start();
 }
 return tracer.newTrace().name(spanName).tag(CALL_PATH, path).start();
}

代码示例来源:origin: jaegertracing/spark-dependencies

@Override
public void createChildSpan(TracingWrapper<ZipkinWrapper> parent) {
 operationName = UUID.randomUUID().toString().replace("-","");
 if (parent == null) {
  // root node we start a new trace
  span = tracing.tracer().newTrace().name(operationName + "-root")
    .start();
 } else {
  brave.Span parentClient = parent.get().tracing.tracer().newChild(parent.get().span.context())
    .kind(Kind.CLIENT)
    .name(operationName + "-client")
    .start();
  // TODO if I finish this later the span is cached
  // and joined with server span and reported as a single span.
  // to properly solve this we have to look into the tags.
  // However there is another problem jaeger adds only one span.kind
  // (even if span contains cs,cr,sr,ss)
  // And it filters out core annotations, so there is no way how to find out
  // that there is a dependency link in this span.
  // https://github.com/jaegertracing/jaeger/issues/451
  parentClient.finish();
  span = tracing.tracer().joinSpan(parentClient.context())
    .name(operationName + "-server")
    .kind(Kind.SERVER)
    .start();
 }
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-kafka-clients

} else {
 span = tracer.newChild(maybeParent);

代码示例来源:origin: xjdr/xio

@Override
 public void channelRead0(ChannelHandlerContext ctx, Request request) throws Exception {
  ByteBuf content =
    Unpooled.copiedBuffer("Here is the default content that is returned", CharsetUtil.UTF_8);
  HttpResponseStatus status = OK;
  Tracer tracer = httpTracing.tracing().tracer();
  if (request.endOfMessage()) {
   request
     .httpTraceInfo()
     .getSpan()
     .ifPresent(
       parent -> {
        if (parent instanceof brave.Span) {
         Span span =
           tracer.newChild(((brave.Span) parent).context()).name("child").start();
         span.finish();
        }
       });
   val response =
     DefaultFullResponse.builder()
       .status(status)
       .headers(new DefaultHeaders())
       .httpTraceInfo(request.httpTraceInfo())
       .status(status)
       .body(content)
       .build();
   ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
  }
 }
}

相关文章