@Override @SuppressWarnings("deprecation") public ListenableFuture<ClientHttpResponse> intercept( HttpRequest request, byte[] body, AsyncClientHttpRequestExecution execution ) throws IOException { // We need to wrap the request with HttpRequestWrapperWithModifiableHeaders so that tracing info can be // propagated on the headers. HttpRequestWrapperWithModifiableHeaders wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(request); if (surroundCallsWithSubspan) { return createAsyncSubSpanAndExecute(wrapperRequest, body, execution); } return propagateTracingHeadersAndExecute(wrapperRequest, body, execution); }
@Override @SuppressWarnings("deprecation") public ListenableFuture<ClientHttpResponse> intercept( HttpRequest request, byte[] body, AsyncClientHttpRequestExecution execution ) throws IOException { // We need to wrap the request with HttpRequestWrapperWithModifiableHeaders so that tracing info can be // propagated on the headers. HttpRequestWrapperWithModifiableHeaders wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(request); if (surroundCallsWithSubspan) { return createAsyncSubSpanAndExecute(wrapperRequest, body, execution); } return propagateTracingHeadersAndExecute(wrapperRequest, body, execution); }
@Test public void createAsyncSubSpanAndExecute_trigger_null_subspanFinisher_in_catch_block_branch_for_code_coverage() { // given Tracer.getInstance().startRequestWithRootSpan("someRootSpan"); TracingState tracingStateBeforeInterceptorCall = TracingState.getCurrentThreadTracingState(); WingtipsAsyncClientHttpRequestInterceptor interceptorSpy = spy(new WingtipsAsyncClientHttpRequestInterceptor( true, tagAndNamingStrategy, tagAndNamingAdapterMock )); RuntimeException explodingSubspanNameMethodEx = new RuntimeException("Intentional exception thrown by getSubspanSpanName()"); doThrow(explodingSubspanNameMethodEx).when(interceptorSpy).getSubspanSpanName( any(HttpRequest.class), any(HttpTagAndSpanNamingStrategy.class), any(HttpTagAndSpanNamingAdapter.class) ); HttpRequestWrapperWithModifiableHeaders wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(requestMock); byte[] body = new byte[]{42}; // when Throwable ex = catchThrowable( () -> interceptorSpy.createAsyncSubSpanAndExecute(wrapperRequest, body, executionMock) ); // then assertThat(ex).isSameAs(explodingSubspanNameMethodEx); verify(interceptorSpy).getSubspanSpanName(wrapperRequest, tagAndNamingStrategy, tagAndNamingAdapterMock); // TracingState should have been reset even though an exception occurred in some unexpected place. assertThat(normalizeTracingState(TracingState.getCurrentThreadTracingState())) .isEqualTo(normalizeTracingState(tracingStateBeforeInterceptorCall)); }