Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RpcRequest.method() as Zipkin span name #221

Merged
merged 1 commit into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public O execute(ClientRequestContext ctx, I req) throws Exception {

ctx.requestLogFuture().thenAcceptBoth(
res.closeFuture(),
(log, unused) -> clientInterceptor.closeSpan(span, createResponseAdapter(ctx, log, res)))
(log, unused) -> closeSpan(ctx, span, log, res))
.exceptionally(CompletionActions::log);

return res;
Expand Down Expand Up @@ -127,6 +127,14 @@ protected List<KeyValueAnnotation> annotations(ClientRequestContext ctx, Request
return annotations;
}


private void closeSpan(ClientRequestContext ctx, Span span, RequestLog req, O res) {
if (req.hasAttr(RequestLog.RPC_REQUEST)) {
span.setName(req.attr(RequestLog.RPC_REQUEST).get().method());
}
clientInterceptor.closeSpan(span, createResponseAdapter(ctx, req, res));
}

protected ClientResponseAdapter createResponseAdapter(
ClientRequestContext ctx, RequestLog req, O res) {

Expand Down Expand Up @@ -174,5 +182,4 @@ public Collection<KeyValueAnnotation> requestAnnotations() {
return Collections.emptyList();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public O serve(ServiceRequestContext ctx, I req) throws Exception {
if (sampled) {
ctx.requestLogFuture().thenAcceptBoth(
res.closeFuture(),
(log, unused) -> serverInterceptor.closeSpan(serverSpan, createResponseAdapter(ctx, log, res)))
(log, unused) -> closeSpan(ctx, serverSpan, log, res))
.exceptionally(CompletionActions::log);
}
return res;
Expand Down Expand Up @@ -136,6 +136,13 @@ protected List<KeyValueAnnotation> annotations(
return annotations;
}

private void closeSpan(ServiceRequestContext ctx, ServerSpan serverSpan, RequestLog req, O res) {
if (req.hasAttr(RequestLog.RPC_REQUEST)) {
serverSpan.getSpan().setName(req.attr(RequestLog.RPC_REQUEST).get().method());
}
serverInterceptor.closeSpan(serverSpan, createResponseAdapter(ctx, req, res));
}

protected ServerResponseAdapter createResponseAdapter(
ServiceRequestContext ctx, RequestLog req, O res) {
final List<KeyValueAnnotation> annotations = annotations(ctx, req, res);
Expand Down Expand Up @@ -171,5 +178,4 @@ public Collection<KeyValueAnnotation> requestAnnotations() {
return Collections.emptyList();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public void testClientInitiatedTrace() throws Exception {
assertThat(spans[3].getAnnotations()).allMatch(a -> "service/bar".equals(a.host.service_name));
assertThat(spans[4].getAnnotations()).allMatch(a -> "client/qux".equals(a.host.service_name));
assertThat(spans[5].getAnnotations()).allMatch(a -> "service/qux".equals(a.host.service_name));

// Check the span names.
assertThat(spans).allMatch(s -> "hello".equals(s.getName()));
}

@Test(timeout = 10000)
Expand Down Expand Up @@ -178,6 +181,9 @@ public void testServiceInitiatedTrace() throws Exception {
assertThat(spans[2].getAnnotations()).allMatch(a -> "service/bar".equals(a.host.service_name));
assertThat(spans[3].getAnnotations()).allMatch(a -> "client/qux".equals(a.host.service_name));
assertThat(spans[4].getAnnotations()).allMatch(a -> "service/qux".equals(a.host.service_name));

// Check the span names.
assertThat(spans).allMatch(s -> "hello".equals(s.getName()));
}

private static class DelegatingCallback implements AsyncMethodCallback<String> {
Expand Down