Migrated from design-system-swarm with fresh git history.
Old project history preserved in /home/overbits/apps/design-system-swarm
Core components:
- MCP Server (Python FastAPI with mcp 1.23.1)
- Claude Plugin (agents, commands, skills, strategies, hooks, core)
- DSS Backend (dss-mvp1 - token translation, Figma sync)
- Admin UI (Node.js/React)
- Server (Node.js/Express)
- Storybook integration (dss-mvp1/.storybook)
Self-contained configuration:
- All paths relative or use DSS_BASE_PATH=/home/overbits/dss
- PYTHONPATH configured for dss-mvp1 and dss-claude-plugin
- .env file with all configuration
- Claude plugin uses ${CLAUDE_PLUGIN_ROOT} for portability
Migration completed: $(date)
🤖 Clean migration with full functionality preserved
113 lines
2.8 KiB
JavaScript
113 lines
2.8 KiB
JavaScript
/**
|
|
* DSS Telemetry - Browser Error Capture
|
|
* Automatically captures all console errors, uncaught exceptions, and promise rejections
|
|
* Sends telemetry to backend for monitoring and auto-fixing
|
|
*/
|
|
(function() {
|
|
'use strict';
|
|
|
|
const TELEMETRY_ENDPOINT = '/api/telemetry/log';
|
|
const originalError = console.error;
|
|
const originalWarn = console.warn;
|
|
|
|
// Buffer for batching (optional optimization)
|
|
let errorBuffer = [];
|
|
let flushTimeout = null;
|
|
|
|
/**
|
|
* Send log data to backend telemetry endpoint
|
|
*/
|
|
function sendLog(data) {
|
|
const payload = JSON.stringify({
|
|
...data,
|
|
timestamp: new Date().toISOString(),
|
|
url: window.location.href,
|
|
userAgent: navigator.userAgent
|
|
});
|
|
|
|
// Use sendBeacon for reliability (works even on page unload)
|
|
if (navigator.sendBeacon) {
|
|
const blob = new Blob([payload], { type: 'application/json' });
|
|
navigator.sendBeacon(TELEMETRY_ENDPOINT, blob);
|
|
} else {
|
|
// Fallback to fetch with keepalive
|
|
fetch(TELEMETRY_ENDPOINT, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: payload,
|
|
keepalive: true
|
|
}).catch(err => {
|
|
// Silently fail - don't want telemetry errors to break the app
|
|
console.debug('[Telemetry] Failed to send log:', err);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 1. Capture Global Uncaught Errors
|
|
*/
|
|
window.addEventListener('error', function(event) {
|
|
sendLog({
|
|
type: 'uncaught',
|
|
level: 'error',
|
|
message: event.message,
|
|
filename: event.filename,
|
|
lineno: event.lineno,
|
|
colno: event.colno,
|
|
stack: event.error?.stack || 'No stack trace available'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 2. Capture Unhandled Promise Rejections
|
|
*/
|
|
window.addEventListener('unhandledrejection', function(event) {
|
|
sendLog({
|
|
type: 'promise',
|
|
level: 'error',
|
|
message: String(event.reason),
|
|
stack: event.reason?.stack || 'No stack trace available'
|
|
});
|
|
});
|
|
|
|
/**
|
|
* 3. Intercept console.error
|
|
*/
|
|
console.error = function(...args) {
|
|
sendLog({
|
|
type: 'console',
|
|
level: 'error',
|
|
message: args.map(arg => {
|
|
if (typeof arg === 'object') {
|
|
try {
|
|
return JSON.stringify(arg);
|
|
} catch {
|
|
return String(arg);
|
|
}
|
|
}
|
|
return String(arg);
|
|
}).join(' ')
|
|
});
|
|
|
|
// Call original console.error so logs still appear in DevTools
|
|
originalError.apply(console, args);
|
|
};
|
|
|
|
/**
|
|
* 4. Optionally capture console.warn (for comprehensive monitoring)
|
|
*/
|
|
console.warn = function(...args) {
|
|
sendLog({
|
|
type: 'console',
|
|
level: 'warn',
|
|
message: args.map(arg => String(arg)).join(' ')
|
|
});
|
|
|
|
originalWarn.apply(console, args);
|
|
};
|
|
|
|
// Log telemetry initialization
|
|
console.debug('[Telemetry] Browser error capture initialized');
|
|
|
|
})();
|