fix(metrics): incorrect mapping of grpc status codes in the grpc_server_grpc_status_code_total metric (#10989)

# Which Problems Are Solved

Requests without errors were mapped being mapped to GRPC status code
`Unknown`, which were then being mapped as HTTP `500` status code.

# How the Problems Are Solved

By deriving the grpc status codes from the error only when there's an
error.
When the error is `nil`, the grpc status code is set to 0 (`OK`).

# Additional Changes

N/A

# Additional Context
- Closes #10884
This commit is contained in:
Gayathri Vijayan
2025-10-28 11:36:18 +01:00
committed by GitHub
parent d5d68aed4b
commit da63abd1ad

View File

@@ -75,7 +75,10 @@ func RegisterGrpcTotalRequestCounter(ctx context.Context) {
} }
func RegisterGrpcRequestCodeCounter(ctx context.Context, path string, err error) { func RegisterGrpcRequestCodeCounter(ctx context.Context, path string, err error) {
statusCode := connect.CodeOf(err) statusCode := connect.Code(codes.OK)
if err != nil {
statusCode = connect.CodeOf(err)
}
var labels = map[string]attribute.Value{ var labels = map[string]attribute.Value{
GrpcMethod: attribute.StringValue(path), GrpcMethod: attribute.StringValue(path),
ReturnCode: attribute.IntValue(runtime.HTTPStatusFromCode(codes.Code(statusCode))), ReturnCode: attribute.IntValue(runtime.HTTPStatusFromCode(codes.Code(statusCode))),