How do you monitor and debug WebSocket connections?

Answer

WebSocket monitoring and debugging uses several tools: (1) Browser DevTools — Chrome/Firefox DevTools Network tab, filter by "WS", shows connection status, all sent/received frames with timestamps and sizes, enabling message-level debugging; (2) Wireshark — for low-level TCP/WebSocket frame inspection, especially useful for debugging protocol-level issues with custom subprotocols; (3) Server-side logging — log connection events (open, close, error), message receipt, and client identifiers; (4) APM tools — New Relic, Datadog, and Dynatrace provide WebSocket connection tracking and error rates in production; (5) Custom metrics — track connections per second, active connections, messages/second, average message size, and close code distribution using Prometheus + Grafana; (6) Socket.IO Admin UI — an official dashboard showing all connected sockets, rooms, and namespaces with the ability to disconnect clients and emit events.