Skip to content

Commit 21ee8b5

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

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/BaseDecorator.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import datadog.trace.api.cache.QualifiedClassNameCache;
1010
import datadog.trace.bootstrap.instrumentation.api.AgentScope;
1111
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
12+
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities;
1213
import datadog.trace.bootstrap.instrumentation.api.Tags;
1314
import java.lang.reflect.Method;
1415
import java.net.Inet4Address;
@@ -86,8 +87,14 @@ public AgentScope onError(final AgentScope scope, final Throwable throwable) {
8687
}
8788

8889
public AgentSpan onError(final AgentSpan span, final Throwable throwable) {
90+
return onError(span, throwable, ErrorPriorities.DEFAULT);
91+
}
92+
93+
public AgentSpan onError(final AgentSpan span, final Throwable throwable, byte errorPriority) {
8994
if (throwable != null) {
90-
span.addThrowable(throwable instanceof ExecutionException ? throwable.getCause() : throwable);
95+
span.addThrowable(
96+
throwable instanceof ExecutionException ? throwable.getCause() : throwable,
97+
errorPriority);
9198
}
9299
return span;
93100
}

dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/decorator/BaseDecoratorTest.groovy

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package datadog.trace.bootstrap.instrumentation.decorator
22

33

44
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
5+
import datadog.trace.bootstrap.instrumentation.api.ErrorPriorities
56
import datadog.trace.bootstrap.instrumentation.api.Tags
67
import datadog.trace.test.util.DDSpecification
78
import spock.lang.Shared
@@ -62,11 +63,7 @@ class BaseDecoratorTest extends DDSpecification {
6263

6364
then:
6465
if (error) {
65-
if (errorPriority != null) {
66-
1 * span.addThrowable(error, errorPriority)
67-
} else {
68-
1 * span.addThrowable(error)
69-
}
66+
1 * span.addThrowable(error, errorPriority != null ? errorPriority : ErrorPriorities.DEFAULT)
7067
}
7168
0 * _
7269

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

+4-2
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,7 +116,7 @@ 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);
119+
super.onError(span, throwable, ErrorPriorities.HTTP_SERVER_DECORATOR);
118120
if (throwable instanceof StatusRuntimeException) {
119121
onStatus(span, ((StatusRuntimeException) throwable).getStatus());
120122
} else if (throwable instanceof StatusException) {

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

+4-2
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,7 +116,7 @@ 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);
119+
super.onError(span, throwable, ErrorPriorities.HTTP_SERVER_DECORATOR);
118120
if (throwable instanceof StatusRuntimeException) {
119121
onStatus(span, ((StatusRuntimeException) throwable).getStatus());
120122
} else if (throwable instanceof StatusException) {

0 commit comments

Comments
 (0)