From 6ab1e68b1a4dda2adac92e2b1f9d5d4157f564d3 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Fri, 15 Mar 2024 13:12:09 -0400 Subject: [PATCH] socket-mode: add more debug logging to low level websocket event handlers (#1757) --- packages/socket-mode/src/SocketModeClient.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/socket-mode/src/SocketModeClient.ts b/packages/socket-mode/src/SocketModeClient.ts index a0dde63b3..90dec7176 100644 --- a/packages/socket-mode/src/SocketModeClient.ts +++ b/packages/socket-mode/src/SocketModeClient.ts @@ -512,33 +512,38 @@ export class SocketModeClient extends EventEmitter { }; let websocket: WebSocket; + let socketId: string; if (this.websocket === undefined) { this.websocket = new WebSocket(url, options); + socketId = 'Primary'; websocket = this.websocket; } else { // Set up secondary websocket // This is used when creating a new connection because the first is about to disconnect this.secondaryWebsocket = new WebSocket(url, options); + socketId = 'Secondary'; websocket = this.secondaryWebsocket; } // Attach event listeners websocket.addEventListener('open', (event) => { + this.logger.debug(`${socketId} WebSocket open event received (connection established)`); this.stateMachine.handle(Event.WebSocketOpen, event); }); websocket.addEventListener('error', (event) => { - this.logger.error(`A WebSocket error occurred: ${event.message}`); + this.logger.error(`${socketId} WebSocket error occurred: ${event.message}`); this.emit('error', websocketErrorWithOriginal(event.error)); }); websocket.on('message', this.onWebSocketMessage.bind(this)); websocket.on('close', (code: number, _data: Buffer) => { + this.logger.debug(`${socketId} WebSocket close event received (code: ${code}, reason: ${_data.toString()})`); this.stateMachine.handle(Event.WebSocketClose, code); }); // Confirm WebSocket connection is still active websocket.on('ping', ((data: Buffer) => { if (this.pingPongLoggingEnabled) { - this.logger.debug(`Received ping from Slack server (data: ${data})`); + this.logger.debug(`${socketId} WebSocket received ping from Slack server (data: ${data})`); } this.startMonitoringPingFromSlack(); // Since the `addEventListener` method does not accept listener with data arg in TypeScript, @@ -547,7 +552,7 @@ export class SocketModeClient extends EventEmitter { websocket.on('pong', ((data: Buffer) => { if (this.pingPongLoggingEnabled) { - this.logger.debug(`Received pong from Slack server (data: ${data})`); + this.logger.debug(`${socketId} WebSocket received pong from Slack server (data: ${data})`); } this.lastPongReceivedTimestamp = new Date().getTime(); // Since the `addEventListener` method does not accept listener with data arg in TypeScript,