Search in sources :

Example 1 with HttpClientParser

use of brave.http.HttpClientParser in project brave by openzipkin.

the class ITHttpClient method supportsPortableCustomization.

@Test
public void supportsPortableCustomization() throws Exception {
    String uri = "/foo?z=2&yAA=1";
    close();
    httpTracing = httpTracing.toBuilder().clientParser(new HttpClientParser() {

        @Override
        public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) {
            customizer.name(adapter.method(req).toLowerCase() + " " + adapter.path(req));
            // just the path is logged by default
            customizer.tag("http.url", adapter.url(req));
            customizer.tag("context.visible", String.valueOf(currentTraceContext.get() != null));
            customizer.tag("request_customizer.is_span", (customizer instanceof brave.Span) + "");
        }

        @Override
        public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp res, Throwable error, SpanCustomizer customizer) {
            super.response(adapter, res, error, customizer);
            customizer.tag("response_customizer.is_span", (customizer instanceof brave.Span) + "");
        }
    }).build().clientOf("remote-service");
    client = newClient(server.getPort());
    server.enqueue(new MockResponse());
    get(client, uri);
    Span span = takeSpan();
    assertThat(span.name()).isEqualTo("get /foo");
    assertThat(span.remoteServiceName()).isEqualTo("remote-service");
    assertThat(span.tags()).containsEntry("http.url", url(uri)).containsEntry("context.visible", "true").containsEntry("request_customizer.is_span", "false").containsEntry("response_customizer.is_span", "false");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HttpClientParser(brave.http.HttpClientParser) HttpAdapter(brave.http.HttpAdapter) SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

SpanCustomizer (brave.SpanCustomizer)1 HttpAdapter (brave.http.HttpAdapter)1 HttpClientParser (brave.http.HttpClientParser)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.junit.Test)1 Span (zipkin2.Span)1