Package brave.rpc

Class RpcClientHandler

java.lang.Object
brave.rpc.RpcClientHandler

public final class RpcClientHandler
extends Object
This standardizes a way to instrument RPC clients, particularly in a way that encourages use of portable customizations via RpcRequestParser and RpcResponseParser.

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. If there was a Throwable, add it to the span
  5. Complete the span

 RpcClientRequestWrapper requestWrapper = new RpcClientRequestWrapper(request);
 Span span = handler.handleSend(requestWrapper); // 1.
 ClientResponse response = null;
 Throwable error = null;
 try (Scope ws = currentTraceContext.newScope(span.context())) { // 2.
   return response = invoke(request); // 3.
 } catch (Throwable e) {
   error = e; // 4.
   throw e;
 } finally {
   RpcClientResponseWrapper responseWrapper =
     new RpcClientResponseWrapper(requestWrapper, response, error);
   handler.handleReceive(responseWrapper, span); // 5.
 }
 
Since:
5.12