Search in sources :

Example 1 with ClientHttpResponseWrapper

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;
    }
}
Also used : Scope(brave.propagation.CurrentTraceContext.Scope) HttpRequestWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Span(brave.Span) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ClientHttpResponseWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper)

Example 2 with ClientHttpResponseWrapper

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();
}
Also used : ClientHttpResponseWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper) Test(org.junit.Test)

Example 3 with ClientHttpResponseWrapper

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();
}
Also used : IOException(java.io.IOException) ClientHttpResponseWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper) Test(org.junit.Test)

Example 4 with ClientHttpResponseWrapper

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);
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) ClientHttpResponseWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper) Test(org.junit.Test)

Example 5 with ClientHttpResponseWrapper

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);
}
Also used : ClientHttpResponseWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper) Test(org.junit.Test)

Aggregations

ClientHttpResponseWrapper (brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper)5 Test (org.junit.Test)4 Span (brave.Span)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 Scope (brave.propagation.CurrentTraceContext.Scope)1 TraceContext (brave.propagation.TraceContext)1 HttpRequestWrapper (brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper)1 IOException (java.io.IOException)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1