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 HttpServerParser.

    This is an example of synchronous instrumentation:

    
     Span span = handler.handleReceive(extractor, 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.handleSend(response, error, span);
     }
     
    • Method Detail

      • handleReceive

        public brave.Span handleReceive​(brave.propagation.TraceContext.Extractor<Req> extractor,
                                        Req request)
        Conditionally joins a span, or starts a new trace, depending on if a trace context was extracted from the request. Tags are added before the span is started.

        This is typically called before the request is processed by the actual library.