Skip to content

Commit

Permalink
fix: better diagnosed gRPC status code in monitor middleware
Browse files Browse the repository at this point in the history
This change aligns status code retrieval from error with what the gRPC
server logic does:
1. status.FromError
2. status.FromContextError

https://github.com/grpc/grpc-go/blob/master/server.go#L1369-L1377
  • Loading branch information
jlourenc authored and talgendler committed Dec 3, 2023
1 parent 3baaae4 commit 02dc3a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion middleware/interceptors/server/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func MonitorGRPCInterceptor(deps gRPCMetricInterceptorsDeps) grpc.UnaryServerInt
}

func gRPCCodeTagValue(err error) string {
s, _ := status.FromError(err)
s, ok := status.FromError(err)
if !ok {
s = status.FromContextError(err)
}
return strconv.Itoa(int(s.Code()))
}

0 comments on commit 02dc3a8

Please sign in to comment.