Search in sources :

Example 16 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class BaseITTracingClientInterceptor method clientParserTest.

@Test
public void clientParserTest() {
    closeClient(client);
    grpcTracing = grpcTracing.toBuilder().clientParser(new GrpcClientParser() {

        @Override
        protected <M> void onMessageSent(M message, SpanCustomizer span) {
            span.tag("grpc.message_sent", message.toString());
            if (tracing.currentTraceContext().get() != null) {
                span.tag("grpc.message_sent.visible", "true");
            }
        }

        @Override
        protected <M> void onMessageReceived(M message, SpanCustomizer span) {
            span.tag("grpc.message_received", message.toString());
            if (tracing.currentTraceContext().get() != null) {
                span.tag("grpc.message_received.visible", "true");
            }
        }

        @Override
        protected <ReqT, RespT> String spanName(MethodDescriptor<ReqT, RespT> methodDescriptor) {
            return methodDescriptor.getType().name();
        }
    }).build();
    client = newClient();
    ScopedSpan parent = tracing.tracer().startScopedSpan("parent");
    try {
        GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    } finally {
        parent.finish();
    }
    MutableSpan span = testSpanHandler.takeRemoteSpan(CLIENT);
    assertThat(span.name()).isEqualTo("UNARY");
    assertThat(span.tags()).containsKeys("grpc.message_received", "grpc.message_sent", "grpc.message_received.visible", "grpc.message_sent.visible");
    testSpanHandler.takeLocalSpan();
}
Also used : MutableSpan(brave.handler.MutableSpan) CurrentSpanCustomizer(brave.CurrentSpanCustomizer) SpanCustomizer(brave.SpanCustomizer) ScopedSpan(brave.ScopedSpan) Test(org.junit.Test)

Example 17 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class HttpClientHandlerTest method handleSend_requestParserDoesntSeeNullWhenUnwrappedNull.

@Test
public void handleSend_requestParserDoesntSeeNullWhenUnwrappedNull() {
    AtomicBoolean reachedAssertion = new AtomicBoolean();
    init(httpTracingBuilder(tracingBuilder()).clientParser(new HttpClientParser() {

        @Override
        public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer span) {
            assertThat(req).isSameAs(NULL_SENTINEL);
            reachedAssertion.set(true);
        }
    }));
    handler.handleSend(request);
    assertThat(reachedAssertion).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SpanCustomizer(brave.SpanCustomizer) Test(org.junit.Test)

Example 18 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class HttpServerHandlerTest method handleSend_responseParserDoesntSeeNullWhenUnwrappedNull.

@Test
public void handleSend_responseParserDoesntSeeNullWhenUnwrappedNull() {
    AtomicBoolean reachedAssertion = new AtomicBoolean();
    init(httpTracingBuilder(tracingBuilder()).serverParser(new HttpServerParser() {

        @Override
        public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp resp, Throwable error, SpanCustomizer span) {
            assertThat(resp).isSameAs(NULL_SENTINEL);
            reachedAssertion.set(true);
        }
    }));
    handler.handleSend(response, null, mock(brave.Span.class));
    assertThat(reachedAssertion).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SpanCustomizer(brave.SpanCustomizer) Span(brave.Span) Test(org.junit.Test)

Example 19 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class BaseITTracingServerInterceptor method serverParserTest.

@Test
public void serverParserTest() throws IOException {
    grpcTracing = grpcTracing.toBuilder().serverParser(new GrpcServerParser() {

        @Override
        protected <M> void onMessageSent(M message, SpanCustomizer span) {
            span.tag("grpc.message_sent", message.toString());
            if (tracing.currentTraceContext().get() != null) {
                span.tag("grpc.message_sent.visible", "true");
            }
        }

        @Override
        protected <M> void onMessageReceived(M message, SpanCustomizer span) {
            span.tag("grpc.message_received", message.toString());
            if (tracing.currentTraceContext().get() != null) {
                span.tag("grpc.message_received.visible", "true");
            }
        }

        @Override
        protected <ReqT, RespT> String spanName(MethodDescriptor<ReqT, RespT> methodDescriptor) {
            return methodDescriptor.getType().name();
        }
    }).build();
    init();
    GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    MutableSpan span = testSpanHandler.takeRemoteSpan(Span.Kind.SERVER);
    assertThat(span.name()).isEqualTo("UNARY");
    assertThat(span.tags().keySet()).containsExactlyInAnyOrder("grpc.message_received", "grpc.message_sent", "grpc.message_received.visible", "grpc.message_sent.visible");
}
Also used : MutableSpan(brave.handler.MutableSpan) CurrentSpanCustomizer(brave.CurrentSpanCustomizer) SpanCustomizer(brave.SpanCustomizer) Test(org.junit.Test)

Example 20 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class ITHttpClient method supportsDeprecatedPortableCustomization.

@Deprecated
@Test
public void supportsDeprecatedPortableCustomization() throws IOException {
    String uri = "/foo/bar?z=2&yAA=1";
    closeClient(client);
    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 tagged 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);
    MutableSpan span = testSpanHandler.takeRemoteSpan(CLIENT);
    assertThat(span.name()).isEqualTo("get /foo/bar");
    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) MutableSpan(brave.handler.MutableSpan) SpanCustomizer(brave.SpanCustomizer) Test(org.junit.Test)

Aggregations

SpanCustomizer (brave.SpanCustomizer)21 Test (org.junit.Test)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 CurrentSpanCustomizer (brave.CurrentSpanCustomizer)5 Span (zipkin2.Span)5 MutableSpan (brave.handler.MutableSpan)4 HelloReply (io.grpc.examples.helloworld.HelloReply)3 HttpServerParser (brave.http.HttpServerParser)2 Metadata (io.grpc.Metadata)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ScopedSpan (brave.ScopedSpan)1 Span (brave.Span)1 HttpAdapter (brave.http.HttpAdapter)1 HttpClientParser (brave.http.HttpClientParser)1 ClientAdapter (brave.http.HttpRequestParserAdapters.ClientAdapter)1 ClientAdapter (brave.http.HttpResponseParserAdapters.ClientAdapter)1 HttpTracing (brave.http.HttpTracing)1 ClientFactory (com.linecorp.armeria.client.ClientFactory)1 ClientFactoryBuilder (com.linecorp.armeria.client.ClientFactoryBuilder)1 ClientOptionsBuilder (com.linecorp.armeria.client.ClientOptionsBuilder)1