@Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { super.request(adapter, req, customizer); customizer.tag("http.url", adapter.url(req)); // just the path is logged by default } };
@Override public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); customizer.tag("response_customizer.is_span", (customizer instanceof brave.Span) + ""); } }).build();
@Bean @ConditionalOnProperty(name = "spring.sleuth.http.legacy.enabled", havingValue = "false", matchIfMissing = true) @ConditionalOnMissingBean HttpServerParser defaultHttpServerParser() { return new HttpServerParser(); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise prm) { Span span = ctx.channel().attr(NettyHttpTracing.SPAN_ATTRIBUTE).get(); if (span == null || !(msg instanceof HttpResponse)) { ctx.write(msg, prm); return; } HttpResponse response = (HttpResponse) msg; // Guard re-scoping the same span SpanInScope spanInScope = ctx.channel().attr(NettyHttpTracing.SPAN_IN_SCOPE_ATTRIBUTE).get(); if (spanInScope == null) spanInScope = tracer.withSpanInScope(span); try { ctx.write(msg, prm); parser.response(adapter, response, null, span.customizer()); } catch (RuntimeException | Error e) { span.error(e); throw e; } finally { spanInScope.close(); // clear scope before reporting span.finish(); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (!(msg instanceof HttpRequest)) { ctx.fireChannelRead(msg); // superclass does not throw return; } HttpRequest request = (HttpRequest) msg; Span span = nextSpan(extractor.extract(request.headers()), request).kind(Span.Kind.SERVER); ctx.channel().attr(NettyHttpTracing.SPAN_ATTRIBUTE).set(span); SpanInScope spanInScope = tracer.withSpanInScope(span); ctx.channel().attr(NettyHttpTracing.SPAN_IN_SCOPE_ATTRIBUTE).set(spanInScope); // Place the span in scope so that downstream code can read trace IDs try { if (!span.isNoop()) { parseChannelAddress(ctx, request, span); parser.request(adapter, request, span.customizer()); span.start(); } ctx.fireChannelRead(msg); spanInScope.close(); } catch (RuntimeException | Error e) { spanInScope.close(); span.error(e).finish(); // the request abended, so finish the span; throw e; } }
@Bean @ConditionalOnProperty(name = "spring.sleuth.http.legacy.enabled", havingValue = "false", matchIfMissing = true) @ConditionalOnMissingBean HttpServerParser defaultHttpServerParser() { return new HttpServerParser(); }
@Override public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); customizer.tag("response_customizer.is_span", (customizer instanceof brave.Span) + ""); } }).build();
@Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { super.request(adapter, req, customizer); customizer.tag("http.url", adapter.url(req)); // just the path is logged by default } };