Skip to content

Commit b4aa9b9

Browse files
committed
Use lower priorities for grpc server errors
1 parent 9f01834 commit b4aa9b9

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

dd-java-agent/instrumentation/armeria-grpc/src/main/java/datadog/trace/instrumentation/armeria/grpc/server/GrpcServerDecorator.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.api.cache.DDCaches;
1010
import datadog.trace.api.naming.SpanNaming;
1111
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
12+
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
1213
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
1314
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
1415
import datadog.trace.bootstrap.instrumentation.decorator.ServerDecorator;
@@ -102,7 +103,8 @@ public <RespT, ReqT> AgentSpan onCall(final AgentSpan span, ServerCall<ReqT, Res
102103
public AgentSpan onStatus(final AgentSpan span, final Status status) {
103104
span.setTag("status.code", status.getCode().name());
104105
span.setTag("status.description", status.getDescription());
105-
return span.setError(SERVER_ERROR_STATUSES.get(status.getCode().value()));
106+
return span.setError(
107+
SERVER_ERROR_STATUSES.get(status.getCode().value()), ErrorPriorities.HTTP_SERVER_DECORATOR);
106108
}
107109

108110
public AgentSpan onClose(final AgentSpan span, final Status status) {
@@ -114,11 +116,13 @@ public AgentSpan onClose(final AgentSpan span, final Status status) {
114116

115117
@Override
116118
public AgentSpan onError(AgentSpan span, Throwable throwable) {
117-
super.onError(span, throwable);
118-
if (throwable instanceof StatusRuntimeException) {
119-
onStatus(span, ((StatusRuntimeException) throwable).getStatus());
120-
} else if (throwable instanceof StatusException) {
121-
onStatus(span, ((StatusException) throwable).getStatus());
119+
if (span != null) {
120+
span.addThrowable(throwable, ErrorPriorities.HTTP_SERVER_DECORATOR);
121+
if (throwable instanceof StatusRuntimeException) {
122+
onStatus(span, ((StatusRuntimeException) throwable).getStatus());
123+
} else if (throwable instanceof StatusException) {
124+
onStatus(span, ((StatusException) throwable).getStatus());
125+
}
122126
}
123127
return span;
124128
}

dd-java-agent/instrumentation/grpc-1.5/src/main/java/datadog/trace/instrumentation/grpc/server/GrpcServerDecorator.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.api.cache.DDCaches;
1010
import datadog.trace.api.naming.SpanNaming;
1111
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
12+
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
1213
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
1314
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
1415
import datadog.trace.bootstrap.instrumentation.decorator.ServerDecorator;
@@ -102,7 +103,8 @@ public <RespT, ReqT> AgentSpan onCall(final AgentSpan span, ServerCall<ReqT, Res
102103
public AgentSpan onStatus(final AgentSpan span, final Status status) {
103104
span.setTag("status.code", status.getCode().name());
104105
span.setTag("status.description", status.getDescription());
105-
return span.setError(SERVER_ERROR_STATUSES.get(status.getCode().value()));
106+
return span.setError(
107+
SERVER_ERROR_STATUSES.get(status.getCode().value()), ErrorPriorities.HTTP_SERVER_DECORATOR);
106108
}
107109

108110
public AgentSpan onClose(final AgentSpan span, final Status status) {
@@ -114,11 +116,13 @@ public AgentSpan onClose(final AgentSpan span, final Status status) {
114116

115117
@Override
116118
public AgentSpan onError(AgentSpan span, Throwable throwable) {
117-
super.onError(span, throwable);
118-
if (throwable instanceof StatusRuntimeException) {
119-
onStatus(span, ((StatusRuntimeException) throwable).getStatus());
120-
} else if (throwable instanceof StatusException) {
121-
onStatus(span, ((StatusException) throwable).getStatus());
119+
if (span != null) {
120+
span.addThrowable(throwable, ErrorPriorities.HTTP_SERVER_DECORATOR);
121+
if (throwable instanceof StatusRuntimeException) {
122+
onStatus(span, ((StatusRuntimeException) throwable).getStatus());
123+
} else if (throwable instanceof StatusException) {
124+
onStatus(span, ((StatusException) throwable).getStatus());
125+
}
122126
}
123127
return span;
124128
}

0 commit comments

Comments
 (0)