From 4dc4f205505bd5267712488d2205ab333c1c4eee Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Jan 2026 03:58:54 +0000 Subject: [PATCH] fix: auto-initialize Prometheus metrics server when enabled The Prometheus metrics server was implemented but never started because initializeMetrics() was never called. This fix adds automatic initialization when the module is loaded and BAILEYS_PROMETHEUS_ENABLED=true. This ensures the /metrics endpoint is available without requiring manual initialization in the application code. --- src/Utils/prometheus-metrics.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Utils/prometheus-metrics.ts b/src/Utils/prometheus-metrics.ts index 27480cb1..378ce449 100644 --- a/src/Utils/prometheus-metrics.ts +++ b/src/Utils/prometheus-metrics.ts @@ -1899,6 +1899,30 @@ export async function shutdownMetrics(): Promise { } } +// ============================================ +// Auto-initialization +// ============================================ + +/** + * Auto-start the Prometheus metrics server when module is loaded + * and BAILEYS_PROMETHEUS_ENABLED=true + * + * This ensures the /metrics endpoint is available without requiring + * manual initialization in the application code. + */ +if (metricsConfig.enabled) { + // Use setImmediate to avoid blocking module loading + setImmediate(() => { + initializeMetrics() + .then(() => { + console.log('[Prometheus] Auto-initialized metrics server successfully') + }) + .catch((error) => { + console.error('[Prometheus] Failed to auto-initialize metrics server:', error) + }) + }) +} + // ============================================ // Default Export // ============================================