Search in sources :

Example 11 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class HttpServerHandlerTest method handleReceive_requestParserDoesntSeeNullWhenUnwrappedNull.

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

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

Example 12 with SpanCustomizer

use of brave.SpanCustomizer in project brave by openzipkin.

the class HttpRequestParserAdaptersTest method parse_parsesInScope.

/**
 * The old http handler always parsed in scope because the parser had no argument for a trace
 * context.
 */
@Test
public void parse_parsesInScope() {
    AtomicBoolean parsed = new AtomicBoolean();
    ClientAdapter parserAdapter = new ClientAdapter(currentTraceContext, new HttpParser() {

        @Override
        public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer span) {
            parsed.set(true);
            assertThat(currentTraceContext.get()).isSameAs(context);
        }
    });
    parserAdapter.parse(mock(HttpClientRequest.class), context, span);
    assertThat(parsed).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientAdapter(brave.http.HttpRequestParserAdapters.ClientAdapter) SpanCustomizer(brave.SpanCustomizer) Test(org.junit.Test)

Example 13 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 14 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 15 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)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