feat(panels): add WebSocket Panel for real-time connection tracking#19
feat(panels): add WebSocket Panel for real-time connection tracking#19JacobCoffee merged 5 commits intomainfrom
Conversation
Implements Phase 10.3 from PLAN.md - WebSocket Panel with: ## Core Features - WebSocketMessage/WebSocketConnection dataclasses for tracking - WebSocketPanel with class-level storage for connection state - Message logging (sent/received) with timestamps and sizes - Connection lifecycle tracking (connecting → connected → closed) - Circular buffer with configurable max messages per connection - Content truncation for large messages (configurable size limits) ## Middleware Integration - WebSocket scope detection in Litestar middleware - Send/receive wrappers for message interception - Close code and reason capture - Graceful error handling (tracking never breaks WebSocket) ## Auto-Detection - Plugin auto-detects WebSocket handlers (@websocket, WebsocketListener) - Automatically adds WebSocketPanel when WebSocket usage detected - Works with both decorator and class-based handlers ## Configuration Options - websocket_tracking_enabled (default: True) - websocket_max_connections (default: 50) - websocket_max_messages_per_connection (default: 100) - websocket_max_message_size (default: 10KB) - websocket_binary_preview_size (default: 256 bytes) - websocket_connection_ttl (default: 1 hour) ## Testing - 30 unit tests for data models and panel - 15 integration tests for middleware - 100% coverage on websocket.py module Includes example app with Echo and Chat WebSocket handlers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
- Change Makefile example targets to use `uv run python` instead of `uv run` to use project venv instead of inline script dependencies - Add example-websocket target - Fix websocket example to not use reload mode (avoids module path issues) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR implements Phase 10.3 from PLAN.md by adding comprehensive WebSocket connection tracking to the debug toolbar. The implementation includes a new WebSocketPanel that monitors WebSocket lifecycle events (connect, message exchange, disconnect), tracks bidirectional message flow with content previews, and provides real-time statistics. The panel is automatically added when WebSocket handlers are detected in the application.
Key Changes
- WebSocket Panel Implementation: New panel with connection tracking, message logging, and statistics (connections, messages, bytes transferred)
- Middleware Enhancement: Extended
DebugToolbarMiddlewareto handle WebSocket scope with message interception wrappers - Auto-Detection: Plugin automatically detects WebSocket handlers (
@websocketdecorator,WebsocketListenerclasses) and adds the panel
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
src/debug_toolbar/core/panels/websocket.py |
Core panel implementation with WebSocketMessage, WebSocketConnection dataclasses and thread-safe connection tracking |
src/debug_toolbar/core/panels/__init__.py |
Exports new WebSocketPanel |
src/debug_toolbar/core/config.py |
Adds WebSocket configuration options (tracking, limits, TTL, preview settings) |
src/debug_toolbar/litestar/middleware.py |
Extends middleware to handle WebSocket scope with send/receive wrappers for message tracking |
src/debug_toolbar/litestar/plugin.py |
Implements auto-detection logic for WebSocket handlers |
src/debug_toolbar/templates/panels/websocket.html |
Responsive UI template showing connection tables, message timeline, and statistics |
examples/websocket_panel_example.py |
Demo application with echo and chat WebSocket handlers |
tests/core/panels/test_websocket.py |
Unit tests for panel, dataclasses, and methods (30 tests) |
tests/integration/test_websocket_integration.py |
Integration tests for middleware WebSocket tracking (15 tests) |
tests/core/panels/__init__.py |
Test package initialization |
tests/core/__init__.py |
Test package initialization |
Comments suppressed due to low confidence (1)
examples/websocket_panel_example.py:35
- Import of 'asyncio' is not used.
import asyncio
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove duplicate Any import in middleware.py - Implement max_connections enforcement to prevent unbounded memory growth - Remove unused config options (websocket_binary_preview_size, websocket_show_binary_preview) - Fix template key mismatches (type/size/preview) - Add debug logging to except clauses in example - Simplify redundant handler.__wrapped__ check in plugin.py - Use cast() instead of type: ignore for message_type - Extract duplicate code between send/receive wrappers into helper method - Fix docstring - remove binary WebSocket reference - Add WebSocket panel screenshot to README and docs - Update PLAN.md to reflect completion of Phase 10.3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update CI workflow to use ruff 0.14.0 instead of 0.9.0 - Add per-file ignore for TC001/TC002 in handlers.py (runtime import) - Fix import order in handlers.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Move logging import to module level in handlers.py - Use dynamic ws/wss protocol for HTTPS support - Fix threading lock with asyncio queue - copy subscribers before iterating 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
Implements Phase 10.3 from PLAN.md - WebSocket Panel with full connection and message tracking capabilities.
Features
@websockethandlers orWebsocketListenerclasses detectedConfiguration Options
Files Changed
src/debug_toolbar/core/panels/websocket.py- New panel with dataclassessrc/debug_toolbar/core/config.py- WebSocket configuration optionssrc/debug_toolbar/litestar/middleware.py- WebSocket scope handlingsrc/debug_toolbar/litestar/plugin.py- Auto-detection logicsrc/debug_toolbar/templates/panels/websocket.html- Panel UIexamples/websocket_panel_example.py- Demo with Echo & ChatTest plan
make lintpassesmake type-checkpasses (no new errors)🤖 Generated with Claude Code