Package brave.http
Class HttpClientHandler<Req,Resp>
- java.lang.Object
-
- brave.http.HttpClientHandler<Req,Resp>
-
- Type Parameters:
Req- the native http request type of the client.Resp- the native http response type of the client.
public final class HttpClientHandler<Req,Resp> extends java.lang.ObjectThis standardizes a way to instrument http clients, particularly in a way that encourages use of portable customizations viaHttpClientParser.This is an example of synchronous instrumentation:
Span span = handler.handleSend(injector, request); Throwable error = null; try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) { // any downstream code can see Tracer.currentSpan() or use Tracer.currentSpanCustomizer() response = invoke(request); } catch (RuntimeException | Error e) { error = e; throw e; } finally { handler.handleReceive(response, error, span); }- Since:
- 4.3
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <Req,Resp>
HttpClientHandler<Req,Resp>create(HttpTracing httpTracing, HttpClientAdapter<Req,Resp> adapter)voidhandleReceive(Resp response, java.lang.Throwable error, brave.Span span)Finishes the client span after assigning it tags according to the response or error.<C> brave.SpanhandleSend(brave.propagation.TraceContext.Injector<C> injector, C carrier, Req request)LikehandleSend(TraceContext.Injector, Object), except for when the carrier of trace data is not the same as the request.<C> brave.SpanhandleSend(brave.propagation.TraceContext.Injector<C> injector, C carrier, Req request, brave.Span span)LikehandleSend(TraceContext.Injector, Object, Object), except explicitly controls the span representing the request.brave.SpanhandleSend(brave.propagation.TraceContext.Injector<Req> injector, Req request)Starts the client span after assigning it a name and tags.brave.SpanhandleSend(brave.propagation.TraceContext.Injector<Req> injector, Req request, brave.Span span)LikehandleSend(TraceContext.Injector, Object), except explicitly controls the span representing the request.brave.SpannextSpan(Req request)Creates a potentially noop span representing this request.
-
-
-
Method Detail
-
create
public static <Req,Resp> HttpClientHandler<Req,Resp> create(HttpTracing httpTracing, HttpClientAdapter<Req,Resp> adapter)
-
handleSend
public brave.Span handleSend(brave.propagation.TraceContext.Injector<Req> injector, Req request)
Starts the client span after assigning it a name and tags. Thisinjectsthe trace context onto the request before returning.Call this before sending the request on the wire.
-
handleSend
public <C> brave.Span handleSend(brave.propagation.TraceContext.Injector<C> injector, C carrier, Req request)LikehandleSend(TraceContext.Injector, Object), except for when the carrier of trace data is not the same as the request.
-
handleSend
public brave.Span handleSend(brave.propagation.TraceContext.Injector<Req> injector, Req request, brave.Span span)
LikehandleSend(TraceContext.Injector, Object), except explicitly controls the span representing the request.- Since:
- 4.4
-
handleSend
public <C> brave.Span handleSend(brave.propagation.TraceContext.Injector<C> injector, C carrier, Req request, brave.Span span)LikehandleSend(TraceContext.Injector, Object, Object), except explicitly controls the span representing the request.- Since:
- 4.4
-
nextSpan
public brave.Span nextSpan(Req request)
Creates a potentially noop span representing this request. This is used when you need to provision a span in a different scope than where the request is executed.- Since:
- 4.4
-
handleReceive
public void handleReceive(@Nullable Resp response, @Nullable java.lang.Throwable error, brave.Span span)Finishes the client span after assigning it tags according to the response or error.This is typically called once the response headers are received, and after the span is
no longer in scope.
-
-