diff --git a/instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/server/GrpcServerInterceptor.java b/instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/server/GrpcServerInterceptor.java index da965e94..f1bc3ef3 100644 --- a/instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/server/GrpcServerInterceptor.java +++ b/instrumentation/grpc-1.6/src/main/java/io/opentelemetry/javaagent/instrumentation/hypertrace/grpc/v1_6/server/GrpcServerInterceptor.java @@ -61,9 +61,9 @@ public ServerCall.Listener interceptCall( FilterResult filterResult = FilterRegistry.getFilter().evaluateRequestHeaders(currentSpan, mapHeaders); if (filterResult.shouldBlock()) { + // map http codes with grpc codes // We cannot send custom message in grpc calls - // TODO: map http codes with grpc codes. filterResult.getBlockingStatusCode() - call.close(Status.PERMISSION_DENIED, new Metadata()); + call.close(mapHttpToGrpcStatus(filterResult.getBlockingStatusCode()), new Metadata()); @SuppressWarnings("unchecked") ServerCall.Listener noop = NoopServerCallListener.INSTANCE; return noop; @@ -78,6 +78,32 @@ public ServerCall.Listener interceptCall( } } + /** + * Mapping according to https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md + */ + private static Status mapHttpToGrpcStatus(int httpStatus) { + switch (httpStatus) { + case 400: + return Status.INTERNAL; + case 401: + return Status.UNAUTHENTICATED; + case 403: + return Status.PERMISSION_DENIED; + case 404: + return Status.UNIMPLEMENTED; + case 429: + return Status.UNAVAILABLE; + case 502: + return Status.UNAVAILABLE; + case 503: + return Status.UNAVAILABLE; + case 504: + return Status.UNAVAILABLE; + default: + return Status.UNKNOWN; + } + } + static final class TracingServerCall extends ForwardingServerCall.SimpleForwardingServerCall {