@Override public void onSuccess(ClientHttpResponse result) { handler.handleReceive(result, null, span); } }
@Override public void onFailure(Throwable ex) { handler.handleReceive(null, ex, span); }
void handleReceive(Span span, Response response, Throwable error) { this.handler.handleReceive(response, error, span); }
@Override public void process(HttpResponse response, HttpContext context) { Span span = (Span) context.getAttribute(Span.class.getName()); if (span == null) return; handler.handleReceive(response, null, span); } }
void handleReceive(Span clientSpan, Tracer.SpanInScope ws, ClientResponse clientResponse, Throwable throwable) { this.handler.handleReceive(clientResponse, throwable, clientSpan); ws.close(); }
@Override public void failed(Exception ex) { Span currentSpan = (Span) context.getAttribute(Span.class.getName()); if (currentSpan != null) { context.removeAttribute(Span.class.getName()); handler.handleReceive(null, ex, currentSpan); } responseConsumer.failed(ex); }
@Override public void failed(Exception ex) { Span currentSpan = (Span) context.getAttribute(Span.class.getName()); if (currentSpan != null) { context.removeAttribute(Span.class.getName()); handler.handleReceive(null, ex, currentSpan); } requestProducer.failed(ex); }
@Override public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { Object storedSpan = exchange.getAttribute(SPAN_ATTRIBUTE); if (storedSpan == null) { return input; } if (log.isDebugEnabled()) { log.debug("Will instrument the response"); } this.handler.handleReceive(exchange.getResponse(), null, (Span) storedSpan); if (log.isDebugEnabled()) { log.debug("The response was handled for span " + storedSpan); } return new HttpHeaders(input); }
protected void handle(HttpClientResponse httpClientResponse, Throwable throwable) { AtomicReference reference = httpClientResponse.currentContext() .getOrDefault(AtomicReference.class, null); if (reference == null || reference.get() == null) { return; } this.handler.handleReceive(httpClientResponse, throwable, (Span) reference.get()); }
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); Request.Builder requestBuilder = request.newBuilder(); Span span = handler.handleSend(injector, requestBuilder, request); parseRouteAddress(chain, span); Response response = null; Throwable error = null; try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { return response = chain.proceed(requestBuilder.build()); } catch (IOException | RuntimeException | Error e) { error = e; throw e; } finally { handler.handleReceive(response, error, span); } }
@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 public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext clientContext, HttpExecutionAware execAware) throws IOException, HttpException { Span span = handler.nextSpan(request); CloseableHttpResponse response = null; Throwable error = null; try (SpanInScope ws = tracer.withSpanInScope(span)) { return response = protocolExec.execute(route, request, clientContext, execAware); } catch (IOException | HttpException | RuntimeException | Error e) { error = e; throw e; } finally { handler.handleReceive(response, error, span); } } }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { Span span = handler.handleSend(injector, request.getHeaders(), request); ClientHttpResponse response = null; Throwable error = null; try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { return response = execution.execute(request, body); } catch (IOException | RuntimeException | Error e) { error = e; throw e; } finally { handler.handleReceive(response, error, span); } }
@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; } }
@Override public void onResponse(Span span, Response response, Throwable error) { handler.handleReceive(response, error, span); }
@Override public Object run() { RequestContext context = RequestContext.getCurrentContext(); ((SpanInScope) context.getRequest().getAttribute(SpanInScope.class.getName())).close(); clientHandler.handleReceive(context.getResponse(), null, tracer.currentSpan()); log.debug("Closed span {} for {}", tracer.currentSpan(), context.getRequest().getMethod()); return null; }
private void saveHeadersAsInvocationContext(RequestContext ctx, Span span) { try { ctx.addZuulRequestHeader(CSE_CONTEXT, JsonUtils.writeValueAsString(ctx.getZuulRequestHeaders())); } catch (JsonProcessingException e) { clientHandler.handleReceive(ctx.getResponse(), e, span); throw new IllegalStateException("Unable to write request headers as json to " + CSE_CONTEXT, e); } }
@Override public ZuulFilterResult runFilter() { RequestContext ctx = RequestContext.getCurrentContext(); Span span = clientHandler.handleSend(injector, ctx); saveHeadersAsInvocationContext(ctx, span); SpanInScope scope = tracer.withSpanInScope(span); log.debug("Generated tracing span {} for {}", span, ctx.getRequest().getMethod()); ctx.getRequest().setAttribute(SpanInScope.class.getName(), scope); ZuulFilterResult result = super.runFilter(); log.debug("Result of Zuul filter is [{}]", result.getStatus()); if (ExecutionStatus.SUCCESS != result.getStatus()) { log.debug("The result of Zuul filter execution was not successful thus will close the current span {}", span); clientHandler.handleReceive(ctx.getResponse(), result.getException(), span); scope.close(); } return result; }
void handleReceive(Span clientSpan, Tracer.SpanInScope ws, ClientResponse clientResponse, Throwable throwable) { this.handler.handleReceive(clientResponse, throwable, clientSpan); ws.close(); }
protected void handle(HttpClientResponse httpClientResponse, Throwable throwable) { AtomicReference reference = httpClientResponse.currentContext() .getOrDefault(AtomicReference.class, null); if (reference == null || reference.get() == null) { return; } this.handler.handleReceive(httpClientResponse, throwable, (Span) reference.get()); }