Search in sources :

Example 1 with HttpRequestWrapper

use of brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper 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 HttpRequestWrapper

use of brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper in project brave by openzipkin.

the class HttpRequestWrapperTest method path_emptyToSlash.

// NOTE: While technically possible, it is not easy to make URI.getPath() return null!
@Test
public void path_emptyToSlash() {
    when(request.getURI()).thenReturn(URI.create("http://localhost"));
    assertThat(new HttpRequestWrapper(request).path()).isEqualTo("/");
}
Also used : HttpRequestWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper) Test(org.junit.Test)

Example 3 with HttpRequestWrapper

use of brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper in project brave by openzipkin.

the class HttpRequestWrapperTest method path.

@Test
public void path() {
    when(request.getURI()).thenReturn(URI.create("http://localhost/api"));
    assertThat(new HttpRequestWrapper(request).path()).isEqualTo("/api");
}
Also used : HttpRequestWrapper(brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper) Test(org.junit.Test)

Aggregations

HttpRequestWrapper (brave.spring.web.TracingClientHttpRequestInterceptor.HttpRequestWrapper)3 Test (org.junit.Test)2 Span (brave.Span)1 CurrentTraceContext (brave.propagation.CurrentTraceContext)1 Scope (brave.propagation.CurrentTraceContext.Scope)1 TraceContext (brave.propagation.TraceContext)1 ClientHttpResponseWrapper (brave.spring.web.TracingClientHttpRequestInterceptor.ClientHttpResponseWrapper)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1