fix span error tagging in grpc server interceptor
This commit is contained in:
parent
df017e044a
commit
6ac07abe2b
|
@ -2,6 +2,9 @@ package datadog.trace.instrumentation.grpc.server;
|
||||||
|
|
||||||
import datadog.trace.agent.decorator.ServerDecorator;
|
import datadog.trace.agent.decorator.ServerDecorator;
|
||||||
import datadog.trace.api.DDSpanTypes;
|
import datadog.trace.api.DDSpanTypes;
|
||||||
|
import io.grpc.Status;
|
||||||
|
import io.opentracing.Span;
|
||||||
|
import io.opentracing.tag.Tags;
|
||||||
|
|
||||||
public class GrpcServerDecorator extends ServerDecorator {
|
public class GrpcServerDecorator extends ServerDecorator {
|
||||||
public static final GrpcServerDecorator DECORATE = new GrpcServerDecorator();
|
public static final GrpcServerDecorator DECORATE = new GrpcServerDecorator();
|
||||||
|
@ -20,4 +23,17 @@ public class GrpcServerDecorator extends ServerDecorator {
|
||||||
protected String component() {
|
protected String component() {
|
||||||
return "grpc-server";
|
return "grpc-server";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Span onClose(final Span span, final Status status) {
|
||||||
|
|
||||||
|
span.setTag("status.code", status.getCode().name());
|
||||||
|
span.setTag("status.description", status.getDescription());
|
||||||
|
|
||||||
|
onError(span, status.getCause());
|
||||||
|
if (!status.isOk()) {
|
||||||
|
Tags.ERROR.set(span, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return span;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,27 @@ public class TracingServerInterceptor implements ServerInterceptor {
|
||||||
this.span = span;
|
this.span = span;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose(final Status status, final Metadata trailers) {
|
||||||
|
DECORATE.onClose(span, status);
|
||||||
|
// Finishes span.
|
||||||
|
try (final Scope scope = tracer.scopeManager().activate(span, false)) {
|
||||||
|
if (scope instanceof TraceScope) {
|
||||||
|
((TraceScope) scope).setAsyncPropagation(true);
|
||||||
|
}
|
||||||
|
delegate().onClose(status, trailers);
|
||||||
|
if (scope instanceof TraceScope) {
|
||||||
|
((TraceScope) scope).setAsyncPropagation(false);
|
||||||
|
}
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
DECORATE.onError(span, e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
DECORATE.beforeFinish(span);
|
||||||
|
span.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(final ReqT message) {
|
public void onMessage(final ReqT message) {
|
||||||
final Scope scope =
|
final Scope scope =
|
||||||
|
@ -178,6 +199,7 @@ public class TracingServerInterceptor implements ServerInterceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReady() {
|
public void onReady() {
|
||||||
try (final Scope scope = tracer.scopeManager().activate(span, false)) {
|
try (final Scope scope = tracer.scopeManager().activate(span, false)) {
|
||||||
|
|
Loading…
Reference in New Issue