@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; } };
@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"; }
@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)); }
@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"; }
@Override public void onException(JMSException exception) { Span span = tracer.currentSpan(); if (span != null) span.error(exception); } }
@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)); }
@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); }
@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); }
@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; }
@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); }
@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); } }
@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; }
@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); } }
private Span startOrContinueRenamedSpan(String spanName) { Span currentSpan = this.tracer.currentSpan(); if (currentSpan != null) { return currentSpan.name(spanName); } return this.tracer.nextSpan().name(spanName); }
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); }; }
@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); } } }
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); }
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 } }
@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); }
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); }; } }