Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket-mode: add more debug logging to low level websocket event handlers #1757

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/socket-mode/src/SocketModeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading