HttpServerHandler extends HttpHandler { public Span handleReceive(HttpServerRequest request) { Span span = nextSpan(defaultExtractor.extract(request), request); return handleStart(request, span); } HttpServerHandler(HttpTracing httpTracing, @Deprecated HttpServerAdapter<Req, Resp> adapter); static HttpServerHandler<HttpServerRequest, HttpServerResponse> create(
    HttpTracing httpTracing); @Deprecated static HttpServerHandler<Req, Resp> create(HttpTracing httpTracing,
    HttpServerAdapter<Req, Resp> adapter); Span handleReceive(HttpServerRequest request); @Deprecated Span handleReceive(Extractor<Req> extractor, Req request); @Deprecated Span handleReceive(Extractor<C> extractor, C carrier, Req request); void handleSend(@Nullable Resp response, @Nullable Throwable error, Span span); void handleSend(HttpServerResponse response, Span span);  }
@Test public void handleReceive_traceIdSamplerSpecialCased() { Sampler sampler = mock(Sampler.class); init(httpTracingBuilder(tracingBuilder().sampler(sampler)) .serverSampler(SamplerFunctions.deferDecision())); assertThat(handler.handleReceive(request).isNoop()).isTrue(); verify(sampler).isSampled(anyLong()); }
@Test public void handleReceive_neverSamplerSpecialCased() { Sampler sampler = mock(Sampler.class); init(httpTracingBuilder(tracingBuilder().sampler(sampler)) .serverSampler(SamplerFunctions.neverSample())); assertThat(handler.handleReceive(request).isNoop()).isTrue(); verifyNoMoreInteractions(sampler); }
@Test public void handleReceive_samplerSeesHttpServerRequest() { SamplerFunction<HttpRequest> serverSampler = mock(SamplerFunction.class); init(httpTracingBuilder(tracingBuilder()).serverSampler(serverSampler)); handler.handleReceive(request); verify(serverSampler).trySample(request); }
@Test public void handleReceive_oldSamplerDoesntSeeNullWhenUnwrappedNull() { AtomicBoolean reachedAssertion = new AtomicBoolean(); init(httpTracingBuilder(tracingBuilder()) .serverSampler(new HttpSampler() { @Override public <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req req) { assertThat(req).isSameAs(NULL_SENTINEL); reachedAssertion.set(true); return true; } })); handler.handleReceive(request); assertThat(reachedAssertion).isTrue(); }
@Test public void handleReceive_requestParserDoesntSeeNullWhenUnwrappedNull() { AtomicBoolean reachedAssertion = new AtomicBoolean(); init(httpTracingBuilder(tracingBuilder()) .serverParser(new HttpServerParser() { @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer span) { assertThat(req).isSameAs(NULL_SENTINEL); reachedAssertion.set(true); } })); handler.handleReceive(request); assertThat(reachedAssertion).isTrue(); }