public Filter before() { return (request, response) -> { Span span = handler.handleReceive(extractor, request, request.raw()); request.attribute(Tracer.SpanInScope.class.getName(), tracer.withSpanInScope(span)); }; }
@Override public void filter(ClientRequestContext request) { Span span = handler.handleSend(injector, request.getHeaders(), request); request.setProperty(SpanInScope.class.getName(), tracer.withSpanInScope(span)); }
@Override protected R getFallback() { Span span = this.span.get(); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) { span.tag(FALLBACK_METHOD_NAME_KEY, getFallbackMethodName()); return doGetFallback(); } finally { span.finish(); this.span.set(null); } }
@Override public void onCancel() { SpanInScope scope = tracer.withSpanInScope(span); try { // retrolambda can't resolve this try/finally delegate().onCancel(); } finally { scope.close(); } }
@Override public void onComplete() { SpanInScope scope = tracer.withSpanInScope(span); try { // retrolambda can't resolve this try/finally delegate().onComplete(); } finally { scope.close(); } }
@Override public void onReady() { SpanInScope scope = tracer.withSpanInScope(span); try { // retrolambda can't resolve this try/finally delegate().onReady(); } finally { scope.close(); } } }
@Override public void send(Message message) throws JMSException { Span span = createAndStartProducerSpan(null, message); SpanInScope ws = tracer.withSpanInScope(span); // animal-sniffer mistakes this for AutoCloseable try { delegate.send(message); } catch (RuntimeException | JMSException | Error e) { span.error(e); throw e; } finally { ws.close(); span.finish(); } }
@Override public RequestEventListener onRequest(RequestEvent requestEvent) { if (requestEvent.getType() == RequestEvent.Type.START) { Span span = serverHandler.handleReceive(extractor, requestEvent.getContainerRequest()); return new TracingRequestEventListener(span, tracer.withSpanInScope(span)); } return null; }
@Override public void onMessage(Message message) { Span listenerSpan = startMessageListenerSpan(message); try (SpanInScope ws = tracer.withSpanInScope(listenerSpan)) { delegate.onMessage(message); } catch (Throwable t) { listenerSpan.error(t); throw t; } finally { listenerSpan.finish(); } }
@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); } } }
/** * 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; }
@Override public void onMessage(ReqT message) { SpanInScope scope = tracer.withSpanInScope(span); try { // retrolambda can't resolve this try/finally parser.onMessageReceived(message, span.customizer()); delegate().onMessage(message); } finally { scope.close(); } }
@Override public void onMessage(RespT message) { SpanInScope scope = tracer.withSpanInScope(span); try { // retrolambda can't resolve this try/finally parser.onMessageReceived(message, span.customizer()); delegate().onMessage(message); } finally { scope.close(); } }
/** * 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; }
@Override public void onClose(Status status, Metadata trailers) { SpanInScope scope = tracer.withSpanInScope(span); try { super.onClose(status, trailers); parser.onClose(status, trailers, span.customizer()); } finally { scope.close(); span.finish(); } } }
@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); }
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(); } }
void joinWithSpanInScope(Tracer tracer, TraceContext context) { Span span = tracer.joinSpan(context).name("encode").start(); try (Tracer.SpanInScope scope = tracer.withSpanInScope(span)) { span.tag("foo", "bar"); span.tag("baz", "qux"); } finally { span.finish(); } }
@Override public ListenableFuture<ClientHttpResponse> intercept(HttpRequest request, byte[] body, AsyncClientHttpRequestExecution execution) throws IOException { Span span = handler.handleSend(injector, request.getHeaders(), request); try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { ListenableFuture<ClientHttpResponse> result = execution.executeAsync(request, body); result.addCallback(new TraceListenableFutureCallback(span, handler)); return result; } catch (IOException | RuntimeException | Error e) { handler.handleReceive(null, e, span); throw e; } }
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(); } }