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;
}
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");
}
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");
}
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);
}
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();
}
Aggregations