Search in sources :

Example 1 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class SpanCustomizingAsyncHandlerInterceptor 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)

Example 2 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class ITTracingClientInterceptor method clientParserTest.

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

        @Override
        protected <M> void onMessageSent(M message, SpanCustomizer span) {
            span.tag("grpc.message_sent", message.toString());
            if (tracing.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.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();
    GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    Span span = spans.take();
    assertThat(span.name()).isEqualTo("unary");
    assertThat(span.tags()).containsKeys("grpc.message_received", "grpc.message_sent", "grpc.message_received.visible", "grpc.message_sent.visible");
}
Also used : SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) Test(org.junit.Test)

Example 3 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class ITTracingServerInterceptor method serverParserTest.

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

        @Override
        protected <M> void onMessageSent(M message, SpanCustomizer span) {
            span.tag("grpc.message_sent", message.toString());
            if (grpcTracing.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 (grpcTracing.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);
    Span span = spans.take();
    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 : SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) Test(org.junit.Test)

Example 4 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class ITTracingServerInterceptor method serverParserTestWithStreamingResponse.

@Test
public void serverParserTestWithStreamingResponse() throws Exception {
    grpcTracing = grpcTracing.toBuilder().serverParser(new GrpcServerParser() {

        int responsesSent = 0;

        @Override
        protected <M> void onMessageSent(M message, SpanCustomizer span) {
            span.tag("grpc.message_sent." + responsesSent++, message.toString());
        }
    }).build();
    init();
    Iterator<HelloReply> replies = GreeterGrpc.newBlockingStub(client).sayHelloWithManyReplies(HELLO_REQUEST);
    assertThat(replies).hasSize(10);
    // all response messages are tagged to the same span
    Span span = spans.take();
    assertThat(span.tags()).hasSize(10);
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) SpanCustomizer(brave.SpanCustomizer) Span(zipkin2.Span) Test(org.junit.Test)

Example 5 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class HttpClientHandlerTest method handleReceive_responseParserDoesntSeeNullWhenUnwrappedNull.

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

        @Override
        public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp resp, Throwable error, SpanCustomizer span) {
            assertThat(resp).isSameAs(NULL_SENTINEL);
            reachedAssertion.set(true);
        }
    }));
    brave.Span span = mock(brave.Span.class);
    when(span.isNoop()).thenReturn(false);
    handler.handleReceive(response, null, span);
    assertThat(reachedAssertion).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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