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.
This commit is contained in:
Claude
2026-01-22 03:58:54 +00:00
parent 77c05b04b8
commit 4dc4f20550
+24
View File
@@ -1899,6 +1899,30 @@ export async function shutdownMetrics(): Promise<void> {
}
}
// ============================================
// 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
// ============================================