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

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

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

Tracer.currentSpan介绍

[英]Returns the current span in scope or null if there isn't one.

When entering user code, prefer #currentSpanCustomizer() as it is a stable type and will never return null.
[中]返回作用域中的当前范围,如果没有,则返回null。
输入用户代码时,请选择#currentSpanCustomizer(),因为它是一个稳定类型,永远不会返回null。

代码示例

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

@Override
  public String call() throws Exception {
    log.info("call");
    int millis = SampleController.this.random.nextInt(1000);
    Thread.sleep(millis);
    SampleController.this.tracer.currentSpan().tag("callable-sleep-millis",
        String.valueOf(millis));
    Span span = SampleController.this.tracer.currentSpan();
    return "async hi: " + span;
  }
};

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

@RequestMapping("/hi2")
public String hi2() throws InterruptedException {
  log.info("hi2");
  int millis = this.random.nextInt(1000);
  Thread.sleep(millis);
  this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
  return "hi2";
}

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

@Async
public void background() throws InterruptedException {
  int millis = this.random.nextInt(1000);
  Thread.sleep(millis);
  this.tracer.currentSpan().tag("background-sleep-millis", String.valueOf(millis));
}

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

@RequestMapping("/hi2")
public String hi2() throws InterruptedException {
  log.info("hi2!");
  int millis = this.random.nextInt(1000);
  Thread.sleep(millis);
  this.tracer.currentSpan().tag("random-sleep-millis", String.valueOf(millis));
  return "hi2";
}

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

@Override public void onException(JMSException exception) {
  Span span = tracer.currentSpan();
  if (span != null) span.error(exception);
 }
}

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

@Async
public void background() throws InterruptedException {
  int millis = this.random.nextInt(1000);
  Thread.sleep(millis);
  this.tracer.currentSpan().tag("background-sleep-millis", String.valueOf(millis));
}

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

@Override
public void afterMessageHandled(Message<?> message, MessageChannel channel,
    MessageHandler handler, Exception ex) {
  if (emptyMessage(message)) {
    return;
  }
  if (log.isDebugEnabled()) {
    log.debug("Will finish the current span after message handled "
        + this.tracer.currentSpan());
  }
  finishSpan(ex);
}

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

@Override
public void afterReceiveCompletion(Message<?> message, MessageChannel channel,
    Exception ex) {
  if (emptyMessage(message)) {
    return;
  }
  if (log.isDebugEnabled()) {
    log.debug("Will finish the current span after receive completion "
        + this.tracer.currentSpan());
  }
  finishSpan(ex);
}

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

@Override
public void filter(ClientRequestContext request, ClientResponseContext response) {
 Span span = tracer.currentSpan();
 if (span == null) return;
 ((Tracer.SpanInScope) request.getProperty(Tracer.SpanInScope.class.getName())).close();
 handler.handleReceive(response, null, span);
}

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

@Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
  if (Tracing.currentTracer().currentSpan() == null) {
   throw new IllegalStateException("couldn't read current span!");
  }
  AsyncContext ctx = req.startAsync();
  ctx.start(ctx::complete);
 }
}

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

@Override
public TraceContext getTraceContext() {
  brave.Tracer tracer = brave.Tracing.currentTracer();
  if (tracer != null) {
    Span span = tracer.currentSpan();
    if (span != null) {
      return new BraveTraceContext(span.context());
    }
  }
  return null;
}

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

@Override public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request,
   HttpClientContext context, HttpExecutionAware execAware)
   throws IOException, HttpException {
  Span span = tracer.currentSpan();
  if (span != null) {
   HttpAdapter.parseTargetAddress(request, span);
   handler.handleSend(injector, request, span);
  }
  return mainExec.execute(route, request, context, execAware);
 }
}

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

public Filter afterAfter() {
 return (request, response) -> {
  Span span = tracer.currentSpan();
  if (span == null) return;
  ((Tracer.SpanInScope) request.attribute(Tracer.SpanInScope.class.getName())).close();
  handler.handleSend(ADAPTER.adaptResponse(request.raw(), response.raw()), null, span);
 };
}

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

@Override public void onException(JMSException exception) {
  Span span = tracer.currentSpan();
  if (span == null) {
   delegate.onException(exception);
   return;
  }
  try (SpanInScope ws = tracer.withSpanInScope(span)) {
   delegate.onException(exception);
  } finally {
   span.error(exception);
  }
 }
}

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

SpanSubscription<T> newCoreSubscriber(Tracing tracing) {
  Span root = this.context.hasKey(Span.class) ? this.context.get(Span.class)
      : tracing.tracer().currentSpan();
  return new ScopePassingSpanSubscriber<>(this.subscriber, this.context, tracing,
      root);
}

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

static <T> CoreSubscriber<? super T> scopePassingSpanSubscription(Tracing tracing,
    CoreSubscriber<? super T> sub) {
  Context context = sub.currentContext();
  Span root = context.hasKey(Span.class) ? context.get(Span.class)
      : tracing.tracer().currentSpan();
  if (root != null) {
    return new ScopePassingSpanSubscriber<>(sub, context, tracing, root);
  }
  else {
    return sub; // no need to trace
  }
}

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

@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
  if (tracer().currentSpan() != null) {
    // clear any previous trace
    tracer().withSpanInScope(null);
  }
  String uri = exchange.getRequest().getPath().pathWithinApplication().value();
  if (log.isDebugEnabled()) {
    log.debug("Received a request to uri [" + uri + "]");
  }
  return new MonoWebFilterTrace(chain.filter(exchange), exchange, this);
}

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

public ExceptionHandler exception(ExceptionHandler delegate) {
  return (exception, request, response) -> {
   Span span = tracer.currentSpan();
   if (span != null) {
    ((Tracer.SpanInScope) request.attribute(Tracer.SpanInScope.class.getName())).close();
    handler.handleSend(ADAPTER.adaptResponse(request.raw(), response.raw()), exception, span);
   }
   delegate.handle(exception, request, response);
  };
 }
}

相关文章