Telemetry: boot-slow beacon names the 3 slowest resources
The first boot-slow capture (5763ms total, html 68ms) proved the white screen happens AFTER the shell arrives — but not which fetch eats the time. Append the 3 slowest resource entries (path, start→end, transferSize; sz0 ≈ served from SW/cache) so the next slow boot names its culprit. Reason cap 300→500 client+server to fit the detail. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+11
-1
@@ -42,7 +42,7 @@
|
||||
function report(reason) {
|
||||
if (sent) return; sent = true; // one beacon per page
|
||||
try {
|
||||
var b = new Blob([JSON.stringify({ reason: String(reason || 'unknown').slice(0, 300),
|
||||
var b = new Blob([JSON.stringify({ reason: String(reason || 'unknown').slice(0, 500),
|
||||
path: location.pathname })], { type: 'application/json' });
|
||||
navigator.sendBeacon && navigator.sendBeacon('/api/client-error', b);
|
||||
} catch (e) { /* best-effort telemetry */ }
|
||||
@@ -73,6 +73,16 @@
|
||||
if (nav && nav.responseStart) detail += ' (html ' + Math.round(nav.responseStart) + 'ms)';
|
||||
if (navigator.connection && navigator.connection.effectiveType)
|
||||
detail += ' on ' + navigator.connection.effectiveType;
|
||||
// Name the culprits: the 3 slowest resource fetches so far, with
|
||||
// start→end so gaps (idle/SW churn) are distinguishable from slow
|
||||
// downloads. size=0 usually means it came from the SW/cache.
|
||||
var res = (performance.getEntriesByType('resource') || [])
|
||||
.slice().sort(function (a, b) { return b.duration - a.duration; }).slice(0, 3)
|
||||
.map(function (r) {
|
||||
var name = r.name.replace(location.origin, '').slice(0, 80);
|
||||
return name + ' ' + Math.round(r.startTime) + '→' + Math.round(r.responseEnd) + 'ms sz' + (r.transferSize || 0);
|
||||
});
|
||||
if (res.length) detail += ' | slowest: ' + res.join(' ; ');
|
||||
report(detail);
|
||||
}
|
||||
} catch (e) { /* timing is best-effort */ }
|
||||
|
||||
+1
-1
@@ -948,7 +948,7 @@ def create_app() -> FastAPI:
|
||||
with get_conn() as conn:
|
||||
conn.execute(
|
||||
"INSERT INTO client_errors (reason, path, user_agent, app_version) VALUES (?, ?, ?, ?)",
|
||||
((body.reason or "")[:300], (body.path or "")[:200], ua, (body.version or "")[:60]),
|
||||
((body.reason or "")[:500], (body.path or "")[:200], ua, (body.version or "")[:60]),
|
||||
)
|
||||
conn.execute("DELETE FROM client_errors WHERE created_at < datetime('now','-14 days')")
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user