WingtipsApacheHttpClientInterceptor implements HttpRequestInterceptor, HttpResponseInterceptor { public static <T extends HttpClientBuilder> T addTracingInterceptors(T builder) { return addTracingInterceptors(builder, true); } WingtipsApacheHttpClientInterceptor();  WingtipsApacheHttpClientInterceptor(boolean surroundCallsWithSubspan);  WingtipsApacheHttpClientInterceptor(
        boolean surroundCallsWithSubspan,
        HttpTagAndSpanNamingStrategy<HttpRequest, HttpResponse> tagAndNamingStrategy,
        HttpTagAndSpanNamingAdapter<HttpRequest, HttpResponse> tagAndNamingAdapter
    ); @Override void process(HttpRequest request, HttpContext context); @Override void process(HttpResponse response, HttpContext context); static T addTracingInterceptors(T builder); static T addTracingInterceptors(T builder, boolean surroundCallsWithSubspan); static final WingtipsApacheHttpClientInterceptor DEFAULT_IMPL; static final HttpRequestInterceptor DEFAULT_REQUEST_IMPL; static final HttpResponseInterceptor DEFAULT_RESPONSE_IMPL; }
@Test public void addTracingInterceptors_single_arg_works_as_expected() { HttpClientBuilder builder = HttpClientBuilder.create(); addTracingInterceptors(builder); HttpClientBuilderInterceptors builderInterceptors = new HttpClientBuilderInterceptors(builder); assertThat(builderInterceptors.firstRequestInterceptors).containsExactly(DEFAULT_REQUEST_IMPL); assertThat(builderInterceptors.lastRequestInterceptors).isNullOrEmpty(); assertThat(builderInterceptors.firstResponseInterceptors).isNullOrEmpty(); assertThat(builderInterceptors.lastResponseInterceptors).containsExactly(DEFAULT_RESPONSE_IMPL); }
@DataProvider(value = { "true", "false" }) @Test public void addTracingInterceptors_double_arg_works_as_expected(boolean subspanOptionOn) { HttpClientBuilder builder = HttpClientBuilder.create(); addTracingInterceptors(builder, subspanOptionOn); HttpClientBuilderInterceptors builderInterceptors = new HttpClientBuilderInterceptors(builder); assertThat(builderInterceptors.firstRequestInterceptors).hasSize(1); assertThat(builderInterceptors.lastResponseInterceptors).hasSize(1); HttpRequestInterceptor requestInterceptor = builderInterceptors.firstRequestInterceptors.get(0); HttpResponseInterceptor responseInterceptor = builderInterceptors.lastResponseInterceptors.get(0); assertThat(requestInterceptor).isInstanceOf(WingtipsApacheHttpClientInterceptor.class); assertThat(responseInterceptor).isInstanceOf(WingtipsApacheHttpClientInterceptor.class); assertThat(((WingtipsApacheHttpClientInterceptor) requestInterceptor).surroundCallsWithSubspan) .isEqualTo(subspanOptionOn); assertThat(((WingtipsApacheHttpClientInterceptor) responseInterceptor).surroundCallsWithSubspan) .isEqualTo(subspanOptionOn); assertThat(builderInterceptors.lastRequestInterceptors).isNullOrEmpty(); assertThat(builderInterceptors.firstResponseInterceptors).isNullOrEmpty(); if (subspanOptionOn) { assertThat(builderInterceptors.firstRequestInterceptors).containsExactly(DEFAULT_REQUEST_IMPL); assertThat(builderInterceptors.lastResponseInterceptors).containsExactly(DEFAULT_RESPONSE_IMPL); } }