Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
package stats
// <!-- START clutchdoc -->
// description: Emits latency, success, and error stats after each request.
// <!-- END clutchdoc -->
import (
const Name = "clutch.middleware.stats"
func New(cfg *any.Any, logger *zap.Logger, scope tally.Scope) (middleware.Middleware, error) {
return &mid{
logger: logger,
scope: scope.SubScope("module"),
}, nil
type mid struct {
logger *zap.Logger
scope tally.Scope
func (m *mid) UnaryInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
service, method, ok := middleware.SplitFullMethod(info.FullMethod)
if !ok {
m.logger.Warn("could not parse gRPC method", zap.String("fullMethod", info.FullMethod))
grpcScope := m.scope.Tagged(map[string]string{
"grpc_service": service,
"grpc_method": method,
t := grpcScope.Timer("rpc_latency").Start()
resp, err := handler(ctx, req)
"grpc_status": status.Convert(err).Code().String(),
return resp, err