Search in sources :

Example 11 with Span

use of zipkin2.proto3.Span in project brave by openzipkin.

the class ITTracingClientInterceptor method addsErrorTag_onCanceledFuture.

@Test
public void addsErrorTag_onCanceledFuture() throws Exception {
    server.enqueueDelay(TimeUnit.SECONDS.toMillis(1));
    ListenableFuture<HelloReply> resp = GreeterGrpc.newFutureStub(client).sayHello(HELLO_REQUEST);
    assumeTrue("lost race on cancel", resp.cancel(true));
    Span span = spans.take();
    assertThat(span.tags()).containsExactly(entry("error", "CANCELLED"), entry("grpc.status_code", "CANCELLED"));
}
Also used : HelloReply(io.grpc.examples.helloworld.HelloReply) Span(zipkin2.Span) Test(org.junit.Test)

Example 12 with Span

use of zipkin2.proto3.Span in project brave by openzipkin.

the class ITTracingServerInterceptor method reportsServerKindToZipkin.

@Test
public void reportsServerKindToZipkin() throws Exception {
    GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    Span span = spans.take();
    assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 13 with Span

use of zipkin2.proto3.Span 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 14 with Span

use of zipkin2.proto3.Span in project brave by openzipkin.

the class ITTracingServerInterceptor method usesExistingTraceId.

@Test
public void usesExistingTraceId() throws Exception {
    final String traceId = "463ac35c9f6413ad";
    final String parentId = traceId;
    final String spanId = "48485a3953bb6124";
    Channel channel = ClientInterceptors.intercept(client, new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {

                @Override
                public void start(Listener<RespT> responseListener, Metadata headers) {
                    headers.put(Key.of("X-B3-TraceId", ASCII_STRING_MARSHALLER), traceId);
                    headers.put(Key.of("X-B3-ParentSpanId", ASCII_STRING_MARSHALLER), parentId);
                    headers.put(Key.of("X-B3-SpanId", ASCII_STRING_MARSHALLER), spanId);
                    headers.put(Key.of("X-B3-Sampled", ASCII_STRING_MARSHALLER), "1");
                    super.start(responseListener, headers);
                }
            };
        }
    });
    GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
    Span span = spans.take();
    assertThat(span.traceId()).isEqualTo(traceId);
    assertThat(span.parentId()).isEqualTo(parentId);
    assertThat(span.id()).isEqualTo(spanId);
    assertThat(span.shared()).isTrue();
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Span(zipkin2.Span) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) ClientCall(io.grpc.ClientCall) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.Test)

Example 15 with Span

use of zipkin2.proto3.Span in project brave by openzipkin.

the class ITTracingServerInterceptor method createsChildWhenJoinDisabled.

@Test
public void createsChildWhenJoinDisabled() throws Exception {
    grpcTracing = GrpcTracing.create(tracingBuilder(NEVER_SAMPLE).supportsJoin(false).build());
    init();
    final String traceId = "463ac35c9f6413ad";
    final String parentId = traceId;
    final String spanId = "48485a3953bb6124";
    Channel channel = ClientInterceptors.intercept(client, new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {

                @Override
                public void start(Listener<RespT> responseListener, Metadata headers) {
                    headers.put(Key.of("X-B3-TraceId", ASCII_STRING_MARSHALLER), traceId);
                    headers.put(Key.of("X-B3-ParentSpanId", ASCII_STRING_MARSHALLER), parentId);
                    headers.put(Key.of("X-B3-SpanId", ASCII_STRING_MARSHALLER), spanId);
                    headers.put(Key.of("X-B3-Sampled", ASCII_STRING_MARSHALLER), "1");
                    super.start(responseListener, headers);
                }
            };
        }
    });
    GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
    Span span = spans.take();
    assertThat(span.traceId()).isEqualTo(traceId);
    assertThat(span.parentId()).isEqualTo(spanId);
    assertThat(span.id()).isNotEqualTo(spanId);
    assertThat(span.shared()).isNull();
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Span(zipkin2.Span) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall) ClientCall(io.grpc.ClientCall) ClientInterceptor(io.grpc.ClientInterceptor) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)290 Test (org.junit.Test)203 Test (org.junit.jupiter.api.Test)69 Endpoint (zipkin2.Endpoint)62 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 ArrayList (java.util.ArrayList)29 V1Span (zipkin2.v1.V1Span)23 List (java.util.List)19 Map (java.util.Map)18 Annotation (zipkin2.Annotation)13 AggregateCall (zipkin2.internal.AggregateCall)13 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)12 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Arrays.asList (java.util.Arrays.asList)9 Span (com.google.devtools.cloudtrace.v2.Span)8 Trace (com.google.devtools.cloudtrace.v1.Trace)7 Call (zipkin2.Call)7 Span (zipkin2.proto3.Span)7