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

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

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

Tracer.nextSpan介绍

[英]Returns a new child span if there's a #currentSpan() or a new trace if there isn't.

Prefer #startScopedSpan(String) if you are tracing a synchronous function or code block.
[中]如果存在#currentSpan(),则返回一个新的子span;如果没有,则返回一个新的跟踪。
如果要跟踪同步函数或代码块,请选择#startScopedSpan(字符串)。

代码示例

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

protected TraceCommand(Tracer tracer, Setter setter) {
  super(setter);
  this.tracer = tracer;
  this.span = new AtomicReference<>(this.tracer.nextSpan());
}

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

private Span findOrCreateSpan(ClientRequest.Builder builder) {
  if (log.isDebugEnabled()) {
    log.debug("Instrumenting WebClient call");
  }
  Span clientSpan = this.handler.handleSend(this.injector, builder,
      this.request, this.tracer.nextSpan());
  if (log.isDebugEnabled()) {
    log.debug("Handled send of " + clientSpan);
  }
  return clientSpan;
}

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

@RequestMapping("/traced")
public String traced() throws InterruptedException {
  log.info("traced");
  Span span = this.tracer.nextSpan().name("http:customTraceEndpoint");
  int millis = this.random.nextInt(1000);
  log.info(String.format("Sleeping for [%d] millis", millis));
  Thread.sleep(millis);
  this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
  String s = this.restTemplate
      .getForObject("http://localhost:" + this.port + "/call", String.class);
  span.finish();
  return "traced/" + s;
}

代码示例来源:origin: lettuce-io/lettuce-core

@Override
public Span nextSpan() {
  return postProcessSpan(tracing.tracer().nextSpan());
}

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

@RequestMapping("/traced")
public String traced() throws InterruptedException {
  Span span = this.tracer.nextSpan().name("http:customTraceEndpoint").start();
  int millis = this.random.nextInt(1000);
  log.info(String.format("Sleeping for [%d] millis", millis));
  Thread.sleep(millis);
  this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
  String s = this.restTemplate
      .getForObject("http://localhost:" + this.port + "/call", String.class);
  span.finish();
  return "traced/" + s;
}

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

/**
 * Creates a potentially noop span representing this request. This is used when you need to
 * provision a span in a different scope than where the request is executed.
 *
 * @since 4.4
 */
public Span nextSpan(Req request) {
 Sampler override = httpSampler.toSampler(adapter, request, sampler);
 return tracer.withSampler(override).nextSpan();
}

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

@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
  tracer.nextSpan().name("child").start().finish();
  resp.setStatus(200);
 }
}

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

private Span startOrContinueRenamedSpan(String spanName) {
  Span currentSpan = this.tracer.currentSpan();
  if (currentSpan != null) {
    return currentSpan.name(spanName);
  }
  return this.tracer.nextSpan().name(spanName);
}

代码示例来源:origin: lettuce-io/lettuce-core

@Override
public Span nextSpan(TraceContext traceContext) {
  if (!(traceContext instanceof BraveTraceContext)) {
    return nextSpan();
  }
  BraveTraceContext braveTraceContext = BraveTraceContext.class.cast(traceContext);
  if (braveTraceContext.traceContext == null) {
    return nextSpan();
  }
  return postProcessSpan(tracing.tracer()
      .nextSpan(TraceContextOrSamplingFlags.create(braveTraceContext.traceContext)));
}

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

/** Creates a potentially noop span representing this request */
Span nextSpan(TraceContextOrSamplingFlags extracted, Req request) {
 Boolean sampled = extracted.sampled();
 // only recreate the context if the http sampler made a decision
 if (sampled == null && (sampled = sampler.trySample(adapter, request)) != null) {
  extracted = extracted.sampled(sampled.booleanValue());
 }
 return extracted.context() != null
   ? tracer.joinSpan(extracted.context())
   : tracer.nextSpan(extracted);
}

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

/** Creates a potentially noop span representing this request */
// copy/pasted from HttpServerHandler.nextSpan
Span nextSpan(TraceContextOrSamplingFlags extracted, HttpRequest request) {
 Boolean sampled = extracted.sampled();
 // only recreate the context if the http sampler made a decision
 if (sampled == null && (sampled = sampler.trySample(adapter, request)) != null) {
  extracted = extracted.sampled(sampled.booleanValue());
 }
 return extracted.context() != null
   ? tracer.joinSpan(extracted.context())
   : tracer.nextSpan(extracted);
}

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

/**
 * Returns the {@link Tracer#nextSpan(TraceContextOrSamplingFlags)} or null if {@link
 * #CURRENT_TRACER} and tracing isn't available.
 */
@Nullable public Span next(TraceContextOrSamplingFlags extracted) {
 Tracer tracer = tracer();
 if (tracer == null) return null;
 Span next = tracer.nextSpan(extracted);
 Object[] spanAndScope = {next, tracer.withSpanInScope(next)};
 getCurrentSpanInScopeStack().addFirst(spanAndScope);
 return next;
}

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

Span nextSpan(ProcessorContext context) {
 TraceContextOrSamplingFlags extracted = extractor.extract(context.headers());
 Span result = tracing.tracer().nextSpan(extracted);
 if (!result.isNoop()) {
  addTags(context, result);
 }
 return result;
}

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

/**
 * Returns the {@link Tracer#nextSpan()} or null if {@link #CURRENT_TRACER} and tracing isn't
 * available.
 */
@Nullable public Span next() {
 Tracer tracer = tracer();
 if (tracer == null) return null;
 Span next = tracer.nextSpan();
 Object[] spanAndScope = {next, tracer.withSpanInScope(next)};
 getCurrentSpanInScopeStack().addFirst(spanAndScope);
 return next;
}

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

void nextWithSpanInScope(Tracer tracer, TraceContextOrSamplingFlags extracted) {
 Span span = tracer.nextSpan(extracted).name("encode").start();
 try (Tracer.SpanInScope scope = tracer.withSpanInScope(span)) {
  span.tag("foo", "bar");
  span.tag("baz", "qux");
 } finally {
  span.finish();
 }
}

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

/**
 * Use this to create a span for processing the given record. Note: the result has no name and is
 * not started.
 *
 * <p>This creates a child from identifiers extracted from the record headers, or a new span if
 * one couldn't be extracted.
 */
public Span nextSpan(ConsumerRecord<?, ?> record) {
 TraceContextOrSamplingFlags extracted = extractAndClearHeaders(record.headers());
 Span result = tracing.tracer().nextSpan(extracted);
 if (extracted.context() == null && !result.isNoop()) {
  addTags(record, result);
 }
 return result;
}

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

@Override
public void subscribe(CoreSubscriber<? super Object> actual) {
  Span span;
  Tracer tracer = this.processor.tracer();
  if (this.span == null) {
    span = tracer.nextSpan();
    this.processor.newSpanParser().parse(this.invocation, this.newSpan, span);
    span.start();
  }
  else {
    span = this.span;
  }
  try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) {
    this.source.subscribe(new SpanSubscriber(actual, this.processor,
        this.invocation, this.span == null, span, this.log, this.hasLog));
  }
}

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

@Override
public void subscribe(CoreSubscriber<? super Object> actual) {
  Span span;
  Tracer tracer = this.processor.tracer();
  if (this.span == null) {
    span = tracer.nextSpan();
    this.processor.newSpanParser().parse(this.invocation, this.newSpan, span);
    span.start();
  }
  else {
    span = this.span;
  }
  try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) {
    this.source.subscribe(new SpanSubscriber(actual, this.processor,
        this.invocation, this.span == null, span, this.log, this.hasLog));
  }
}

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

void handleReceive(Message message) {
 if (message == null || tracing.isNoop()) return;
 // remove prior propagation headers from the message
 TraceContextOrSamplingFlags extracted = jmsTracing.extractAndClearMessage(message);
 Span span = tracer.nextSpan(extracted);
 if (!span.isNoop()) {
  span.name("receive").kind(Span.Kind.CONSUMER);
  Destination destination = destination(message);
  if (destination != null) jmsTracing.tagQueueOrTopic(destination, span);
  if (remoteServiceName != null) span.remoteServiceName(remoteServiceName);
  // incur timestamp overhead only once
  long timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
  span.start(timestamp).finish(timestamp);
 }
 jmsTracing.setNextParent(message, span.context());
}

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

相关文章