diff --git a/Sources/App/Core/AppMetrics.swift b/Sources/App/Core/AppMetrics.swift index 2ec692b17..2c3fb00d1 100644 --- a/Sources/App/Core/AppMetrics.swift +++ b/Sources/App/Core/AppMetrics.swift @@ -26,9 +26,11 @@ enum AppMetrics { static func bootstrap() { // prevent tests from boostrapping multiple times guard !initialized.withLock({ $0 }) else { return } - defer { initialized.withLock{ $0 = true } } - let client = PrometheusClient() - MetricsSystem.bootstrap(PrometheusMetricsFactory(client: client)) + initialized.withLock { + let client = PrometheusClient() + MetricsSystem.bootstrap(PrometheusMetricsFactory(client: client)) + $0 = true + } } // metrics