HttpClientHandler extends HttpHandler { public Span handleSend(HttpClientRequest request) { if (request == null) throw new NullPointerException("request == null"); return handleSend(request, tracer.nextSpan(httpSampler, request)); } HttpClientHandler(HttpTracing httpTracing, @Deprecated HttpClientAdapter<Req, Resp> adapter); static HttpClientHandler<HttpClientRequest, HttpClientResponse> create(
    HttpTracing httpTracing); @Deprecated static HttpClientHandler<Req, Resp> create(HttpTracing httpTracing,
    HttpClientAdapter<Req, Resp> adapter); Span handleSend(HttpClientRequest request); Span handleSendWithParent(HttpClientRequest request, @Nullable TraceContext parent); Span handleSend(HttpClientRequest request, Span span); @Deprecated Span handleSend(Injector<Req> injector, Req request); @Deprecated Span handleSend(Injector<C> injector, C carrier, Req request); @Deprecated Span handleSend(Injector<Req> injector, Req request, Span span); @Deprecated Span handleSend(Injector<C> injector, C carrier, Req request, Span span); @Deprecated Span nextSpan(Req request); @Deprecated void handleReceive(@Nullable Resp response, @Nullable Throwable error, Span span); void handleReceive(HttpClientResponse response, Span span);  }
@Test public void handleSend_traceIdSamplerSpecialCased() { Sampler sampler = mock(Sampler.class); init(httpTracingBuilder(tracingBuilder().sampler(sampler)) .clientSampler(SamplerFunctions.deferDecision())); assertThat(handler.handleSend(request).isNoop()).isTrue(); verify(sampler).isSampled(anyLong()); }
@Test public void handleSend_neverSamplerSpecialCased() { Sampler sampler = mock(Sampler.class); init(httpTracingBuilder(tracingBuilder().sampler(sampler)) .clientSampler(SamplerFunctions.neverSample())); assertThat(handler.handleSend(request).isNoop()).isTrue(); verifyNoMoreInteractions(sampler); }
@Test public void handleSend_samplerSeesHttpClientRequest() { SamplerFunction<HttpRequest> clientSampler = mock(SamplerFunction.class); init(httpTracingBuilder(tracingBuilder()).clientSampler(clientSampler)); handler.handleSend(request); verify(clientSampler).trySample(request); }
@Test public void handleSend_oldSamplerDoesntSeeNullWhenUnwrappedNull() { AtomicBoolean reachedAssertion = new AtomicBoolean(); init(httpTracingBuilder(tracingBuilder()) .clientSampler(new HttpSampler() { @Override public <Req> Boolean trySample(HttpAdapter<Req, ?> adapter, Req req) { assertThat(req).isSameAs(NULL_SENTINEL); reachedAssertion.set(true); return true; } })); handler.handleSend(request); assertThat(reachedAssertion).isTrue(); }
@Test public void handleSend_requestParserDoesntSeeNullWhenUnwrappedNull() { AtomicBoolean reachedAssertion = new AtomicBoolean(); init(httpTracingBuilder(tracingBuilder()) .clientParser(new HttpClientParser() { @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer span) { assertThat(req).isSameAs(NULL_SENTINEL); reachedAssertion.set(true); } })); handler.handleSend(request); assertThat(reachedAssertion).isTrue(); }