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 Object
This standardizes a way to instrument http clients, particularly in a way that encourages use of portable customizations via HttpRequestParser and HttpResponseParser.

Synchronous interception is the most straight forward instrumentation.

You generally need to:

  1. Start the span and add trace headers to the request
  2. Put the span in scope so things like log integration works
  3. Invoke the request
  4. Catch any errors
  5. Complete the span

 HttpClientRequestWrapper wrapper = new HttpClientRequestWrapper(request);
 Span span = handler.handleSend(wrapper); // 1.
 Result result = null;
 Throwable error = null;
 try (Scope ws = currentTraceContext.newScope(span.context())) { // 2.
   return result = invoke(request); // 3.
 } catch (Throwable e) {
   error = e; // 4.
   throw e;
 } finally {
   HttpClientResponseWrapper response = result != null
     ? new HttpClientResponseWrapper(wrapper, result, error)
     : null;
   handler.handleReceive(response, error, span); // 5.
 }
 
Since:
4.3