Skip to content

Commit

Permalink
refactor: Add duration field to log error with method in RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jul 3, 2024
1 parent 068be06 commit 347101a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,13 @@ func (x *Xatu) startGrpcServer(ctx context.Context) error {
grpc.ChainUnaryInterceptor(
grpc.UnaryServerInterceptor(grpc_prometheus.UnaryServerInterceptor),
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
start := time.Now()

resp, err := handler(ctx, req)
if err != nil {
x.log.
WithField("method", info.FullMethod).
WithField("duration", time.Since(start)).
WithError(err).
Error("RPC Error")
}
Expand Down

0 comments on commit 347101a

Please sign in to comment.