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:
@@ -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
|
||||
// ============================================
|
||||
|
||||
Reference in New Issue
Block a user