use of brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper in project brave by openzipkin.
the class TracingAsyncClientHttpRequestInterceptor method intercept.
@Override
public ListenableFuture<ClientHttpResponse> intercept(HttpRequest req, byte[] body, AsyncClientHttpRequestExecution execution) throws IOException {
HttpRequestWrapper request = new HttpRequestWrapper(req);
Span span = handler.handleSend(request);
// avoid context sync overhead when we are the root span
TraceContext invocationContext = span.context().parentIdAsLong() != 0 ? currentTraceContext.get() : null;
try (Scope ws = currentTraceContext.maybeScope(span.context())) {
ListenableFuture<ClientHttpResponse> result = execution.executeAsync(req, body);
result.addCallback(new TraceListenableFutureCallback(request, span, handler));
return invocationContext != null ? new TraceContextListenableFuture<>(result, currentTraceContext, invocationContext) : result;
} catch (Throwable e) {
handler.handleReceive(new ClientHttpResponseWrapper(request, null, e), span);
throw e;
}
}
use of brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper in project brave by openzipkin.
the class ClientHttpResponseWrapperTest method statusCode_zeroOnIAE.
@Test
public void statusCode_zeroOnIAE() throws IOException {
when(response.getRawStatusCode()).thenThrow(new IllegalArgumentException());
assertThat(new ClientHttpResponseWrapper(request, response, null).statusCode()).isZero();
}
use of brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper in project brave by openzipkin.
the class ClientHttpResponseWrapperTest method statusCode_zeroOnIOE.
@Test
public void statusCode_zeroOnIOE() throws IOException {
when(response.getRawStatusCode()).thenThrow(new IOException());
assertThat(new ClientHttpResponseWrapper(request, response, null).statusCode()).isZero();
}
use of brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper in project brave by openzipkin.
the class ClientHttpResponseWrapperTest method statusCode_fromHttpStatusCodeException.
@Test
public void statusCode_fromHttpStatusCodeException() {
HttpClientErrorException ex = new HttpClientErrorException(HttpStatus.BAD_REQUEST);
assertThat(new ClientHttpResponseWrapper(request, null, ex).statusCode()).isEqualTo(400);
}
use of brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper in project brave by openzipkin.
the class ClientHttpResponseWrapperTest method statusCode.
@Test
public void statusCode() throws IOException {
when(response.getRawStatusCode()).thenReturn(200);
assertThat(new ClientHttpResponseWrapper(request, response, null).statusCode()).isEqualTo(200);
}
Aggregations