Skip to content

Commit

Permalink
std/grpc: logging: log error detail types that are being sent back to…
Browse files Browse the repository at this point in the history
… callers (and whether it was a natural status).
  • Loading branch information
hugosantos committed Aug 6, 2024
1 parent 4ecf5e1 commit 9c3e650
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion std/grpc/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
"namespacelabs.dev/foundation/std/go/core"
nsgrpc "namespacelabs.dev/foundation/std/grpc"
"namespacelabs.dev/foundation/std/grpc/requestid"
Expand Down Expand Up @@ -69,7 +70,15 @@ func (interceptor) unary(ctx context.Context, req interface{}, info *grpc.UnaryS
if err == nil {
logger.Info().Str("kind", "grpclog").Dur("took", time.Since(rdata.Started)).Str("what", "response").Str("response_body", SerializeMessage(resp)).Send()
} else {
logger.Info().Str("kind", "grpclog").Dur("took", time.Since(rdata.Started)).Str("what", "response").Err(err).Send()
st, ok := status.FromError(err)

var detailTypes []string
for _, det := range st.Proto().GetDetails() {
detailTypes = append(detailTypes, det.TypeUrl)
}

logger.Err(err).Str("kind", "grpclog").Dur("took", time.Since(rdata.Started)).Str("what", "response").
Bool("status_ok", ok).Strs("error_detail_types", detailTypes).Send()
}
}
return resp, err
Expand Down

0 comments on commit 9c3e650

Please sign in to comment.