Package brave.http

Class HttpServerHandler<Req,​Resp>

java.lang.Object
brave.http.HttpServerHandler<Req,​Resp>
Type Parameters:
Req - the native http request type of the server.
Resp - the native http response type of the server.

public final class HttpServerHandler<Req,​Resp>
extends Object
This standardizes a way to instrument http servers, 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. Extract any trace IDs from headers and start the span
  2. Put the span in scope so things like log integration works
  3. Process the request
  4. Catch any errors
  5. Complete the span

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