Covariant approach to magnetic anisotropy