@@ -118,15 +118,26 @@ func MetricsHandler(telemetryRegistry *prometheus.Registry, c *Config) http.Hand
118
118
return mux
119
119
}
120
120
121
- // the server has a deadline set, so we consider it a normal condition
122
- // this makes sure we don't log them as errors
123
121
var defaultCodeToLevel = grpclog .WithLevels (func (code codes.Code ) grpclog.Level {
124
122
if code == codes .DeadlineExceeded {
123
+ // The server has a deadline set, so we consider it a normal condition.
124
+ // This ensures that we don't log them as errors.
125
125
return grpclog .LevelInfo
126
126
}
127
127
return grpclog .DefaultServerCodeToLevel (code )
128
128
})
129
129
130
+ var dispatchDefaultCodeToLevel = grpclog .WithLevels (func (code codes.Code ) grpclog.Level {
131
+ switch code {
132
+ case codes .OK , codes .Canceled :
133
+ return grpclog .LevelDebug
134
+ case codes .NotFound , codes .AlreadyExists , codes .InvalidArgument , codes .Unauthenticated :
135
+ return grpclog .LevelWarn
136
+ default :
137
+ return grpclog .DefaultServerCodeToLevel (code )
138
+ }
139
+ })
140
+
130
141
var durationFieldOption = grpclog .WithDurationField (func (duration time.Duration ) grpclog.Fields {
131
142
return grpclog.Fields {"grpc.time_ms" , duration .Milliseconds ()}
132
143
})
@@ -376,15 +387,15 @@ func DefaultDispatchMiddleware(logger zerolog.Logger, authFunc grpcauth.AuthFunc
376
387
return []grpc.UnaryServerInterceptor {
377
388
requestid .UnaryServerInterceptor (requestid .GenerateIfMissing (true )),
378
389
logmw .UnaryServerInterceptor (logmw .ExtractMetadataField (string (requestmeta .RequestIDKey ), "requestID" )),
379
- grpclog .UnaryServerInterceptor (InterceptorLogger (logger ), defaultCodeToLevel , durationFieldOption , traceIDFieldOption ),
390
+ grpclog .UnaryServerInterceptor (InterceptorLogger (logger ), dispatchDefaultCodeToLevel , durationFieldOption , traceIDFieldOption ),
380
391
grpcMetricsUnaryInterceptor ,
381
392
grpcauth .UnaryServerInterceptor (authFunc ),
382
393
datastoremw .UnaryServerInterceptor (ds ),
383
394
servicespecific .UnaryServerInterceptor ,
384
395
}, []grpc.StreamServerInterceptor {
385
396
requestid .StreamServerInterceptor (requestid .GenerateIfMissing (true )),
386
397
logmw .StreamServerInterceptor (logmw .ExtractMetadataField (string (requestmeta .RequestIDKey ), "requestID" )),
387
- grpclog .StreamServerInterceptor (InterceptorLogger (logger ), defaultCodeToLevel , durationFieldOption , traceIDFieldOption ),
398
+ grpclog .StreamServerInterceptor (InterceptorLogger (logger ), dispatchDefaultCodeToLevel , durationFieldOption , traceIDFieldOption ),
388
399
grpcMetricsStreamingInterceptor ,
389
400
grpcauth .StreamServerInterceptor (authFunc ),
390
401
datastoremw .StreamServerInterceptor (ds ),
0 commit comments