Skip to content

Commit

Permalink
Adds note about status cause
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Apr 27, 2020
1 parent 23a4be5 commit 5433f3b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions instrumentation/grpc/src/main/java/brave/grpc/GrpcParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package brave.grpc;

import brave.ErrorParser;
import brave.Span;
import brave.SpanCustomizer;
import brave.Tracing;
import brave.internal.Nullable;
Expand Down Expand Up @@ -50,19 +51,18 @@ protected <ReqT, RespT> String spanName(MethodDescriptor<ReqT, RespT> methodDesc

/**
* Override to change what data from the status or trailers are parsed into the span modeling it.
* By default, this tags "grpc.status_code" when it is not OK.
* By default, this tags "grpc.status_code" when it is not OK, and "error" if there was no {@link
* Status#getCause()}.
*
* <p><em>Note</em>: {@link Status#getCause()} will be set as {@link Span#error(Throwable)} by
* default. You don't need to parse it here.
*/
protected void onClose(Status status, Metadata trailers, SpanCustomizer span) {
if (status == null || status.isOk()) return;

String code = String.valueOf(status.getCode());
span.tag("grpc.status_code", code);
Throwable cause = status.getCause();
if (cause != null) {
errorParser().error(status.getCause(), span);
} else {
span.tag("error", code);
}
if (status.getCause() == null) span.tag("error", code);
}

static @Nullable String method(String fullMethodName) {
Expand Down

0 comments on commit 5433f3b

Please sign in to comment.