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:
owensmallwood
2024-04-16 08:30:51 -06:00
committed by GitHub
parent a12669951b
commit 8c8885ef23
10 changed files with 262 additions and 67 deletions
@@ -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
}
}
+1
View File
@@ -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),
),
),