Package brave.http

Class 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. If there was a Throwable, add it to the span
    5. Complete the span
    
     HttpServerRequestWrapper requestWrapper = new HttpServerRequestWrapper(request);
     Span span = handler.handleReceive(requestWrapper); // 1.
     HttpServerResponse response = null;
     Throwable error = null;
     try (Scope ws = currentTraceContext.newScope(span.context())) { // 2.
       return response = process(request); // 3.
     } catch (Throwable e) {
       error = e; // 4.
       throw e;
     } finally {
       HttpServerResponseWrapper responseWrapper =
         new HttpServerResponseWrapper(requestWrapper, response, error);
       handler.handleSend(responseWrapper, span); // 5.
     }
     
    Since:
    4.3