Search in sources :

Example 6 with SpanCustomizer

use of brave.SpanCustomizer 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)

Example 7 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class SpanCustomizingApplicationEventListener method onEvent.

@Override
public void onEvent(RequestEvent event) {
    // Note: until REQUEST_MATCHED, we don't know metadata such as if the request is async or not
    if (event.getType() != REQUEST_MATCHED)
        return;
    ContainerRequest request = event.getContainerRequest();
    SpanCustomizer span = (SpanCustomizer) request.getProperty(SpanCustomizer.class.getName());
    if (span == null)
        return;
    request.setProperty("http.route", route(event.getContainerRequest()));
    parser.requestMatched(event, span);
}
Also used : ContainerRequest(org.glassfish.jersey.server.ContainerRequest) SpanCustomizer(brave.SpanCustomizer)

Example 8 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class ITTracingClientInterceptor method clientParserTestStreamingResponse.

@Test
public void clientParserTestStreamingResponse() throws Exception {
    closeClient(client);
    tracing = tracing.toBuilder().clientParser(new GrpcClientParser() {

        int receiveCount = 0;

        @Override
        protected <M> void onMessageReceived(M message, SpanCustomizer span) {
            span.tag("grpc.message_received." + receiveCount++, message.toString());
        }
    }).build();
    client = newClient();
    Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HelloRequest.newBuilder().setName("this is dog").build());
    assertThat(replies).hasSize(10);
    Span span = spans.take();
    // all response messages are tagged to the same span
    assertThat(span.tags()).hasSize(10);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) Test(org.junit.Test)

Example 9 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class ITHttpServer method supportsPortableCustomization.

@Test
public void supportsPortableCustomization() throws Exception {
    httpTracing = httpTracing.toBuilder().serverParser(new HttpServerParser() {

        @Override
        public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) {
            // 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();
    init();
    String uri = "/foo?z=2&yAA=1";
    get(uri);
    Span span = takeSpan();
    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 : SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) HttpServerParser(brave.http.HttpServerParser) Test(org.junit.Test)

Example 10 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class SpanCustomizingHandlerInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) {
    SpanCustomizer span = (SpanCustomizer) request.getAttribute(SpanCustomizer.class.getName());
    if (span != null) {
        setHttpRouteAttribute(request);
        handlerParser.preHandle(request, o, span);
    }
    return true;
}
Also used : SpanCustomizer(brave.SpanCustomizer)

Aggregations

SpanCustomizer (brave.SpanCustomizer)10 Span (zipkin2.Span)7 Test (org.junit.Test)6 HttpServerParser (brave.http.HttpServerParser)2 HelloReply (io.grpc.examples.helloworld.HelloReply)2 HttpAdapter (brave.http.HttpAdapter)1 HttpClientParser (brave.http.HttpClientParser)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)1