Storage Api: Adds traces (#85391)
- adds traces and improved logging to the unified storage server - add a configurable logger to the gRPC server service
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package interceptors
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func LoggingUnaryInterceptor(cfg *setting.Cfg, logger log.Logger) grpc.UnaryServerInterceptor {
|
||||
return func(
|
||||
ctx context.Context,
|
||||
req any,
|
||||
info *grpc.UnaryServerInfo,
|
||||
handler grpc.UnaryHandler,
|
||||
) (resp any, err error) {
|
||||
resp, err = handler(ctx, req)
|
||||
if cfg.GRPCServerEnableLogging {
|
||||
ctxLogger := logger.FromContext(ctx)
|
||||
if err != nil {
|
||||
ctxLogger.Error("gRPC call", "method", info.FullMethod, "req", req, "err", err)
|
||||
} else {
|
||||
ctxLogger.Info("gRPC call", "method", info.FullMethod, "req", req, "resp", resp)
|
||||
}
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ func ProvideService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, authe
|
||||
grpc_middleware.ChainUnaryServer(
|
||||
grpcAuth.UnaryServerInterceptor(authenticator.Authenticate),
|
||||
interceptors.TracingUnaryInterceptor(tracer),
|
||||
interceptors.LoggingUnaryInterceptor(s.cfg, s.logger), // needs to be registered after tracing interceptor to get trace id
|
||||
middleware.UnaryServerInstrumentInterceptor(grpcRequestDuration),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user