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 java.lang.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 Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <Req,​Resp>
      HttpServerHandler<Req,​Resp>
      create​(HttpTracing httpTracing, HttpServerAdapter<Req,​Resp> adapter)  
      <C> brave.Span handleReceive​(brave.propagation.TraceContext.Extractor<C> extractor, C carrier, Req request)
      Like handleReceive(TraceContext.Extractor, Object), except for when the carrier of trace data is not the same as the request.
      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.
      void handleSend​(Resp response, java.lang.Throwable error, brave.Span span)
      Finishes the server span after assigning it tags according to the response or error.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.

      • handleSend

        public void handleSend​(@Nullable
                               Resp response,
                               @Nullable
                               java.lang.Throwable error,
                               brave.Span span)
        Finishes the server span after assigning it tags according to the response or error.

        This is typically called once the response headers are sent, and after the span is no longer in scope.

        See Also:
        HttpServerParser.response(HttpAdapter, Object, Throwable, SpanCustomizer)