fix: auto-initialize Prometheus metrics server when enabled

fix: auto-initialize Prometheus metrics server when enabled
This commit is contained in:
Renato Alcara
2026-01-22 01:03:27 -03:00
committed by GitHub
+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
// ============================================