Skip to content

Commit

Permalink
include client address
Browse files Browse the repository at this point in the history
  • Loading branch information
jchappelow committed Oct 13, 2023
1 parent 283399a commit 0374aca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/services/grpc_server/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
)

Expand Down Expand Up @@ -45,8 +46,11 @@ func SimpleInterceptorLogger(l *log.Logger) grpc.UnaryServerInterceptor {
fields := []zap.Field{
zap.String("method", strings.Trim(info.FullMethod, "/")),
zap.String("elapsed", fmt.Sprintf("%.3fms", elapsedMs)),
zap.String("code", code.String()),
}
if peer, ok := peer.FromContext(ctx); ok {
fields = append(fields, zap.String("addr", peer.Addr.String()))
}
fields = append(fields, zap.String("code", code.String()))
var msg string
if err != nil {
msg = "call failure"
Expand Down

0 comments on commit 0374aca

Please sign in to comment.