func DefaultClientInterceptors()

in grpc/interceptor/interceptor.go [58:88]


func DefaultClientInterceptors(options ClientInterceptorLogOptions) []grpc.UnaryClientInterceptor {
	var apiHandler log.Handler

	apiHandlerOptions := &log.HandlerOptions{
		ReplaceAttr: func(groups []string, a log.Attr) log.Attr {
			a.Key = strings.TrimPrefix(a.Key, "grpc.")
			a.Key = strings.ReplaceAll(a.Key, ".", "_")
			return a
		},
	}

	if _, ok := options.Logger.Handler().(*log.JSONHandler); ok {
		apiHandler = log.NewJSONHandler(options.APIOutput, apiHandlerOptions)
	} else {
		apiHandler = log.NewTextHandler(options.APIOutput, apiHandlerOptions)
	}

	apiHandler = apiHandler.WithAttrs(options.Attributes)

	apiRequestLogger := log.New(apiHandler).With("source", "ApiRequestLog")
	return []grpc.UnaryClientInterceptor{
		retry.UnaryClientInterceptor(common.GetRetryOptions()...),
		mdforward.UnaryClientInterceptor(),
		logging.UnaryClientInterceptor(
			autologger.InterceptorLogger(apiRequestLogger),
			logging.WithLogOnEvents(logging.FinishCall),
			logging.WithLevels(logging.DefaultServerCodeToLevel),
			logging.WithFieldsFromContext(common.GetFields),
		),
	}
}