use of io.opencensus.proto.trace.v1.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"));
}
use of io.opencensus.proto.trace.v1.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);
}
use of io.opencensus.proto.trace.v1.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");
}
use of io.opencensus.proto.trace.v1.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();
}
use of io.opencensus.proto.trace.v1.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();
}
Aggregations