Refactor logMetrics auth code