$filter->getRequestVar() is the correct way because if you have category in filter then $filter->getAttributeModel()->getAttributeCode() will throw error "The attribute model is not defined".