Move metrics increment logic and debug logging outside try block