use of brave.SpanCustomizer in project brave by openzipkin.
the class BaseITTracingClientInterceptor method clientParserTest.
@Test
public void clientParserTest() {
closeClient(client);
grpcTracing = grpcTracing.toBuilder().clientParser(new GrpcClientParser() {
@Override
protected <M> void onMessageSent(M message, SpanCustomizer span) {
span.tag("grpc.message_sent", message.toString());
if (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.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();
ScopedSpan parent = tracing.tracer().startScopedSpan("parent");
try {
GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
} finally {
parent.finish();
}
MutableSpan span = testSpanHandler.takeRemoteSpan(CLIENT);
assertThat(span.name()).isEqualTo("UNARY");
assertThat(span.tags()).containsKeys("grpc.message_received", "grpc.message_sent", "grpc.message_received.visible", "grpc.message_sent.visible");
testSpanHandler.takeLocalSpan();
}
use of brave.SpanCustomizer in project brave by openzipkin.
the class HttpClientHandlerTest method handleSend_requestParserDoesntSeeNullWhenUnwrappedNull.
@Test
public void handleSend_requestParserDoesntSeeNullWhenUnwrappedNull() {
AtomicBoolean reachedAssertion = new AtomicBoolean();
init(httpTracingBuilder(tracingBuilder()).clientParser(new HttpClientParser() {
@Override
public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer span) {
assertThat(req).isSameAs(NULL_SENTINEL);
reachedAssertion.set(true);
}
}));
handler.handleSend(request);
assertThat(reachedAssertion).isTrue();
}
use of brave.SpanCustomizer in project brave by openzipkin.
the class HttpServerHandlerTest method handleSend_responseParserDoesntSeeNullWhenUnwrappedNull.
@Test
public void handleSend_responseParserDoesntSeeNullWhenUnwrappedNull() {
AtomicBoolean reachedAssertion = new AtomicBoolean();
init(httpTracingBuilder(tracingBuilder()).serverParser(new HttpServerParser() {
@Override
public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp resp, Throwable error, SpanCustomizer span) {
assertThat(resp).isSameAs(NULL_SENTINEL);
reachedAssertion.set(true);
}
}));
handler.handleSend(response, null, mock(brave.Span.class));
assertThat(reachedAssertion).isTrue();
}
use of brave.SpanCustomizer in project brave by openzipkin.
the class BaseITTracingServerInterceptor method serverParserTest.
@Test
public void serverParserTest() throws IOException {
grpcTracing = grpcTracing.toBuilder().serverParser(new GrpcServerParser() {
@Override
protected <M> void onMessageSent(M message, SpanCustomizer span) {
span.tag("grpc.message_sent", message.toString());
if (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.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);
MutableSpan span = testSpanHandler.takeRemoteSpan(Span.Kind.SERVER);
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 ITHttpClient method supportsDeprecatedPortableCustomization.
@Deprecated
@Test
public void supportsDeprecatedPortableCustomization() throws IOException {
String uri = "/foo/bar?z=2&yAA=1";
closeClient(client);
httpTracing = httpTracing.toBuilder().clientParser(new HttpClientParser() {
@Override
public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) {
customizer.name(adapter.method(req).toLowerCase() + " " + adapter.path(req));
// just the path is tagged 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().clientOf("remote-service");
client = newClient(server.getPort());
server.enqueue(new MockResponse());
get(client, uri);
MutableSpan span = testSpanHandler.takeRemoteSpan(CLIENT);
assertThat(span.name()).isEqualTo("get /foo/bar");
assertThat(span.remoteServiceName()).isEqualTo("remote-service");
assertThat(span.tags()).containsEntry("http.url", url(uri)).containsEntry("context.visible", "true").containsEntry("request_customizer.is_span", "false").containsEntry("response_customizer.is_span", "false");
}
Aggregations