Skip to content

Commit ae81663

Browse files
authoredJan 19, 2024
add grpc mappings for blocking status code (#399)
1 parent 4570eef commit ae81663

File tree

1 file changed

+28
-2
lines changed
  • instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/server

1 file changed

+28
-2
lines changed
 

‎instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/server/GrpcServerInterceptor.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
6161
FilterResult filterResult =
6262
FilterRegistry.getFilter().evaluateRequestHeaders(currentSpan, mapHeaders);
6363
if (filterResult.shouldBlock()) {
64+
// map http codes with grpc codes
6465
// We cannot send custom message in grpc calls
65-
// TODO: map http codes with grpc codes. filterResult.getBlockingStatusCode()
66-
call.close(Status.PERMISSION_DENIED, new Metadata());
66+
call.close(mapHttpToGrpcStatus(filterResult.getBlockingStatusCode()), new Metadata());
6767
@SuppressWarnings("unchecked")
6868
ServerCall.Listener<ReqT> noop = NoopServerCallListener.INSTANCE;
6969
return noop;
@@ -78,6 +78,32 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
7878
}
7979
}
8080

81+
/**
82+
* Mapping according to https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md
83+
*/
84+
private static Status mapHttpToGrpcStatus(int httpStatus) {
85+
switch (httpStatus) {
86+
case 400:
87+
return Status.INTERNAL;
88+
case 401:
89+
return Status.UNAUTHENTICATED;
90+
case 403:
91+
return Status.PERMISSION_DENIED;
92+
case 404:
93+
return Status.UNIMPLEMENTED;
94+
case 429:
95+
return Status.UNAVAILABLE;
96+
case 502:
97+
return Status.UNAVAILABLE;
98+
case 503:
99+
return Status.UNAVAILABLE;
100+
case 504:
101+
return Status.UNAVAILABLE;
102+
default:
103+
return Status.UNKNOWN;
104+
}
105+
}
106+
81107
static final class TracingServerCall<ReqT, RespT>
82108
extends ForwardingServerCall.SimpleForwardingServerCall<ReqT, RespT> {
83109

0 commit comments

Comments
 (0)
Please sign in to comment.