diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index cdbf87719..b082573f1 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -94,10 +94,11 @@ class WebsocketHandler { throw new Error('WebSocket.Server is not set'); } - this.wss.on('connection', (client: WebSocket) => { + this.wss.on('connection', (client: WebSocket, req) => { this.numConnected++; + client['remoteAddress'] = req.headers['x-forwarded-for'] || req.socket?.remoteAddress || 'unknown'; client.on('error', (e) => { - logger.info('websocket client error: ' + (e instanceof Error ? e.message : e)); + logger.info(`websocket client error from ${client['remoteAddress']}: ` + (e instanceof Error ? e.message : e)); client.close(); }); client.on('close', () => { @@ -285,7 +286,7 @@ class WebsocketHandler { client.send(serializedResponse); } } catch (e) { - logger.debug('Error parsing websocket message: ' + (e instanceof Error ? e.message : e)); + logger.debug(`Error parsing websocket message from ${client['remoteAddress']}: ` + (e instanceof Error ? e.message : e)); client.close(); } });