- 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(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 Deprecated Methods Modifier and Type Method Description static HttpClientHandler<HttpClientRequest,HttpClientResponse>create(HttpTracing httpTracing)static <Req,Resp>
HttpClientHandler<Req,Resp>create(HttpTracing httpTracing, HttpClientAdapter<Req,Resp> adapter)Deprecated.Since 5.7, usecreate(HttpTracing)as it is more portable.voidhandleReceive(Resp response, java.lang.Throwable error, Span span)Finishes the client span after assigning it tags according to the response or error.SpanhandleSend(HttpClientRequest request)Starts the client span after assigning it a name and tags.SpanhandleSend(HttpClientRequest request, Span span)LikehandleSend(HttpClientRequest), except explicitly controls the span representing the request.<C> SpanhandleSend(TraceContext.Injector<C> injector, C carrier, Req request)Deprecated.Since 5.7, usehandleSend(HttpClientRequest).<C> SpanhandleSend(TraceContext.Injector<C> injector, C carrier, Req request, Span span)Deprecated.Since 5.7, usehandleSend(HttpClientRequest).SpanhandleSend(TraceContext.Injector<Req> injector, Req request)Deprecated.Since 5.7, usehandleSend(HttpClientRequest), as this allows more advanced samplers to be used.SpanhandleSend(TraceContext.Injector<Req> injector, Req request, Span span)Deprecated.Since 5.7, usehandleSend(HttpClientRequest, Span).SpannextSpan(Req request)Deprecated.since 5.8 useTracer.nextSpan(SamplerFunction, Object)
-
-
-
Method Detail
-
create
public static HttpClientHandler<HttpClientRequest,HttpClientResponse> create(HttpTracing httpTracing)
- Since:
- 5.7
-
create
@Deprecated public static <Req,Resp> HttpClientHandler<Req,Resp> create(HttpTracing httpTracing, HttpClientAdapter<Req,Resp> adapter)
Deprecated.Since 5.7, usecreate(HttpTracing)as it is more portable.- Since:
- 4.3
-
handleSend
public Span handleSend(HttpClientRequest 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.
- Since:
- 5.7
-
handleSend
public Span handleSend(HttpClientRequest request, Span span)
LikehandleSend(HttpClientRequest), except explicitly controls the span representing the request.- Since:
- 5.7
-
handleSend
@Deprecated public Span handleSend(TraceContext.Injector<Req> injector, Req request)
Deprecated.Since 5.7, usehandleSend(HttpClientRequest), as this allows more advanced samplers to be used.- Since:
- 4.3
-
handleSend
@Deprecated public <C> Span handleSend(TraceContext.Injector<C> injector, C carrier, Req request)
Deprecated.Since 5.7, usehandleSend(HttpClientRequest).- Since:
- 4.3
-
handleSend
@Deprecated public Span handleSend(TraceContext.Injector<Req> injector, Req request, Span span)
Deprecated.Since 5.7, usehandleSend(HttpClientRequest, Span).- Since:
- 4.4
-
handleSend
@Deprecated public <C> Span handleSend(TraceContext.Injector<C> injector, C carrier, Req request, Span span)
Deprecated.Since 5.7, usehandleSend(HttpClientRequest).- Since:
- 4.4
-
nextSpan
@Deprecated public Span nextSpan(Req request)
Deprecated.since 5.8 useTracer.nextSpan(SamplerFunction, Object)- Since:
- 4.4
-
handleReceive
public void handleReceive(@Nullable Resp response, @Nullable java.lang.Throwable error, 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.- Since:
- 4.3
- See Also:
HttpClientParser.response(HttpAdapter, Object, Throwable, SpanCustomizer)
-
-