feat: add connection_errors_total metric tracking
Added recordConnectionError() function and integrated it into socket.ts
to track connection errors by type:
- connection_closed
- connection_lost
- connection_replaced
- timed_out
- logged_out
- bad_session
- restart_required
- multidevice_mismatch
- error_{code} for other status codes
This commit is contained in:
@@ -54,6 +54,7 @@ import {
|
||||
jidEncode,
|
||||
S_WHATSAPP_NET
|
||||
} from '../WABinary'
|
||||
import { recordConnectionError } from '../Utils/prometheus-metrics'
|
||||
import { BinaryInfo } from '../WAM/BinaryInfo.js'
|
||||
import { USyncQuery, USyncUser } from '../WAUSync/'
|
||||
import { WebSocketClient } from './Client'
|
||||
@@ -730,6 +731,41 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
closed = true
|
||||
logger.info({ trace: error?.stack }, error ? 'connection errored' : 'connection closed')
|
||||
|
||||
// Record connection error metric
|
||||
if (error) {
|
||||
const statusCode = (error as Boom)?.output?.statusCode || 0
|
||||
let errorType = 'unknown'
|
||||
switch (statusCode) {
|
||||
case DisconnectReason.connectionClosed:
|
||||
errorType = 'connection_closed'
|
||||
break
|
||||
case DisconnectReason.connectionLost:
|
||||
errorType = 'connection_lost'
|
||||
break
|
||||
case DisconnectReason.connectionReplaced:
|
||||
errorType = 'connection_replaced'
|
||||
break
|
||||
case DisconnectReason.timedOut:
|
||||
errorType = 'timed_out'
|
||||
break
|
||||
case DisconnectReason.loggedOut:
|
||||
errorType = 'logged_out'
|
||||
break
|
||||
case DisconnectReason.badSession:
|
||||
errorType = 'bad_session'
|
||||
break
|
||||
case DisconnectReason.restartRequired:
|
||||
errorType = 'restart_required'
|
||||
break
|
||||
case DisconnectReason.multideviceMismatch:
|
||||
errorType = 'multidevice_mismatch'
|
||||
break
|
||||
default:
|
||||
errorType = `error_${statusCode}`
|
||||
}
|
||||
recordConnectionError(errorType)
|
||||
}
|
||||
|
||||
clearInterval(keepAliveReq)
|
||||
clearTimeout(qrTimer)
|
||||
|
||||
|
||||
@@ -1922,6 +1922,18 @@ export function recordBufferOverflow(): void {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a connection error
|
||||
* Used by socket.ts when connection fails
|
||||
*/
|
||||
export function recordConnectionError(errorType: string): void {
|
||||
try {
|
||||
metrics.connectionErrors?.inc({ error_type: errorType })
|
||||
} catch {
|
||||
// Metrics not initialized, ignore silently
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// Global Instance
|
||||
// ============================================
|
||||
|
||||
Reference in New Issue
Block a user