-
Notifications
You must be signed in to change notification settings - Fork 0
Remote Debug Logging System #174
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
Changes from all commits
0970ab3
44b58f3
d2e45bf
dcad59f
1726104
06f4f92
324df24
8e92343
ca269e2
1e3e524
6282341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,26 +8,287 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { WebBleConnection, Constants, Packet, BufferUtils } from "./mc/index.js"; // your BLE client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ---- Debug Configuration ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Enable debug logging via URL parameter (?debug=true) or set default here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Enable debug logging via URL parameter (?debug=1) or set default here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const urlParams = new URLSearchParams(window.location.search); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const DEBUG_ENABLED = urlParams.get('debug') === 'true' || false; // Set to true to enable debug logging by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const DEBUG_ENABLED = urlParams.get('debug') === '1' || false; // Set to true to enable debug logging by default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ---- Remote Debug Configuration ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Enable remote debug logging via URL parameters (?debuguser=1&debugkey=<key>) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // When enabled, all console output is batched and POSTed to meshmapper.net/livedebug.php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_USER = urlParams.get('debuguser') === '1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_KEY = urlParams.get('debugkey') || null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let REMOTE_DEBUG_ENABLED = REMOTE_DEBUG_USER && REMOTE_DEBUG_KEY; // Can be disabled on no_session error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Remote Debug Queue State | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_ENDPOINT = 'https://meshmapper.net/livedebug.php'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_BATCH_MAX = 100; // Maximum logs per batch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_FLUSH_INTERVAL_MS = 15000; // Flush every 15 seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_RATE_LIMIT = 20; // Max logs per second | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_RATE_RESET_MS = 1000; // Rate limit reset interval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const REMOTE_DEBUG_GRACE_PERIOD_MS = 10000; // Grace period before rate limiting starts (15 seconds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const debugLogQueue = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messages: [], // Array of {date: <epoch>, message: <string>} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flushTimerId: null, // Timer ID for periodic flush | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rateResetTimerId: null, // Timer ID for rate limit reset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logsThisSecond: 0, // Current rate counter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| droppedCount: 0, // Logs dropped due to rate limiting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isProcessing: false, // Lock to prevent concurrent flush | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| startupTimestamp: Date.now() // App launch time for grace period tracking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Store original console methods before overriding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originalConsoleLog = console.log.bind(console); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originalConsoleWarn = console.warn.bind(console); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originalConsoleError = console.error.bind(console); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Queue a log message for remote debug submission | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Handles rate limiting (10/sec) and batch size limits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Handles rate limiting (10/sec) and batch size limits | |
| * Handles rate limiting (20/sec) and batch size limits |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment says "bypass rate limiting for first 15 seconds" but REMOTE_DEBUG_GRACE_PERIOD_MS is 10000ms (10 seconds). This comment should be updated to accurately state "first 10 seconds" to match the constant value.
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both retry attempts fail (neither succeeds nor gets a no_session error), the messages in messagesToSend are permanently lost because they were already removed from debugLogQueue.messages at line 122. Consider re-queuing failed messages back to debugLogQueue.messages so they can be retried in the next flush cycle, similar to how the wardrive API queue handles failures.
| // If we reach here, both attempts failed without a no_session disabling remote debug. | |
| // Re-queue the messages so they can be retried on the next flush cycle. | |
| if (REMOTE_DEBUG_ENABLED && messagesToSend.length > 0) { | |
| // Prepend the failed batch ahead of any new messages queued during this submit | |
| debugLogQueue.messages = messagesToSend.concat(debugLogQueue.messages); | |
| originalConsoleWarn( | |
| `[REMOTE DEBUG] Re-queued ${messagesToSend.length} debug logs after failed submit attempts` | |
| ); | |
| } |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Log when grace period expires (once at 15 seconds)" but REMOTE_DEBUG_GRACE_PERIOD_MS is 10000ms (10 seconds). This inconsistency should be corrected to say "once at 10 seconds" to match the actual grace period duration.
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The console method overrides (console.log, console.warn, console.error) are always active regardless of whether REMOTE_DEBUG_ENABLED is true. This means every console call goes through an extra function call even when remote debugging is disabled. Consider conditionally applying these overrides only when REMOTE_DEBUG_ENABLED is true to avoid unnecessary overhead in production.
| // These overrides call the original method AND queue for remote submission | |
| console.log = function(...args) { | |
| originalConsoleLog(...args); | |
| queueRemoteDebugLog('log', args); | |
| }; | |
| console.warn = function(...args) { | |
| originalConsoleWarn(...args); | |
| queueRemoteDebugLog('warn', args); | |
| }; | |
| console.error = function(...args) { | |
| originalConsoleError(...args); | |
| queueRemoteDebugLog('error', args); | |
| }; | |
| // These overrides call the original method AND queue for remote submission, | |
| // but are only applied when remote debugging is enabled to avoid overhead. | |
| if (REMOTE_DEBUG_ENABLED) { | |
| console.log = function(...args) { | |
| originalConsoleLog(...args); | |
| queueRemoteDebugLog('log', args); | |
| }; | |
| console.warn = function(...args) { | |
| originalConsoleWarn(...args); | |
| queueRemoteDebugLog('warn', args); | |
| }; | |
| console.error = function(...args) { | |
| originalConsoleError(...args); | |
| queueRemoteDebugLog('error', args); | |
| }; | |
| } |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using navigator.sendBeacon with a string payload, the Content-Type header is set to "text/plain" by default, which may cause the server to reject the request if it expects "application/json". Consider creating a Blob with the correct Content-Type: new Blob([payload], { type: 'application/json' }) instead of passing the raw JSON string.
| navigator.sendBeacon(REMOTE_DEBUG_ENDPOINT, payload); | |
| const beaconBody = new Blob([payload], { type: 'application/json' }); | |
| navigator.sendBeacon(REMOTE_DEBUG_ENDPOINT, beaconBody); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Grace period before rate limiting starts (15 seconds)" but the constant value is 10000ms (10 seconds). This inconsistency could confuse developers. The comment should be updated to match the actual value of 10 seconds.