fix(admin): split uncoded errors by crash site, label signed-in visitors, scope external calls

- Errors without a code are grouped by their first app stack frame (or the
  logging module), so unrelated TypeErrors no longer share one issue.
- "visitor" is a signed-in user with no role on the repository; it is no
  longer shown as "not signed in". Anonymous viewers are counted apart.
- The issue page no longer offers "Open user" next to "Open repository":
  users and repositories are counted from different records.
- With a service, repository or user filter, failed external calls are looked
  up by the faults' request IDs instead of the newest 2000 calls overall.
- The page says when the 2000-failure cap was reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 16:35:34 +00:00
1 parent d3860f29ad
commit fdd8f58944
7 files changed
+74 -22

No files matched your search

+22 -8
View File
@@ -45,7 +45,7 @@ const NETWORK_CODES = new Set(["ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTF
const IGNORED = new Set(["process_heartbeat", "queue_heartbeat", "process_started", "job_started", "job_completed", "deployment"]);
// Request envelopes repeat a failure that a more specific record of the same request describes.
const ENVELOPES = new Set(["edge_request", "request_completed"]);
const SIGNED_IN = new Set(["owner", "coauthor", "admin"]);
const ACCOUNT_ROLES = new Set(["owner", "coauthor", "admin"]);
export const statusOf = (row: Row) => Number(row.status || row.httpStatus) || 0;
const codeOf = (row: Row) => String(row.errorCode || row.errorType || (row.event === "edge_request" ? `edge_${statusOf(row) || "5xx"}` : row.event) || "unknown");
@@ -64,18 +64,30 @@ export function recordKind(row: Row): RecordKind {
return "issue";
}
/**
* Without an error code, the code or type alone says little: every TypeError in
* the API would share one issue. The first app stack frame (or the module that
* logged it) tells those crash sites apart.
*/
function uncodedSite(row: Row) {
if (row.errorCode || row.event === "edge_request") return "";
return firstFrame(row.errorStack) || String(row.module || "");
}
export function issueTitle(row: Row) {
const code = codeOf(row);
if (TITLES[code]) return TITLES[code];
if (row.event === "edge_request") return `Edge proxy returned ${statusOf(row) || "5xx"}`;
if (!row.errorCode && row.errorType) return `Code crashed: ${row.errorType}`;
if (row.event === "job_failed" && !row.errorCode) return "Background job failed";
return code.replace(/_/g, " ").replace(/^./, c => c.toUpperCase());
const site = uncodedSite(row);
const at = site ? ` in ${site}` : "";
if (!row.errorCode && row.errorType) return `Code crashed: ${row.errorType}${at}`;
if (row.event === "job_failed" && !row.errorCode) return `Background job failed${at}`;
return code.replace(/_/g, " ").replace(/^./, c => c.toUpperCase()) + at;
}
export function issueId(row: Row) {
// One cause (a GitHub limit, an outage) hits many routes: routes are listed inside the issue.
return createHash("sha256").update(JSON.stringify([codeOf(row), String(row.service || "")])).digest("hex").slice(0, 16);
return createHash("sha256").update(JSON.stringify([codeOf(row), String(row.service || ""), uncodedSite(row)])).digest("hex").slice(0, 16);
}
const time = (row: Row) => Date.parse(String(row.timestamp));
@@ -84,7 +96,8 @@ const seconds = (ms: number) => ms >= 1000 ? `${(ms / 1000).toFixed(1).replace(/
const plural = (n: number, word: string) => `${n.toLocaleString("en-US")} ${word}${n === 1 ? "" : "s"}`;
const hostLabel = (host: string) => host === "storage" ? "Storage" : /github/.test(host) ? "GitHub" : host === "other" ? "An external service" : host;
function firstFrame(stack: unknown) {
const line = String(stack || "").split("\n").find(value => /\(?[\w./-]+\.[jt]s:\d+/.test(value));
// The first frame in our code: dependencies and Node internals say little about the crash site.
const line = String(stack || "").split("\n").find(value => /\(?[\w./-]+\.[jt]s:\d+/.test(value) && !/node_modules|node:/.test(value));
const match = line?.match(/([\w-]+\.[jt]s):(\d+)/);
return match ? `${match[1]}:${match[2]}` : "";
}
@@ -207,8 +220,9 @@ export function buildIssues(rows: Row[], options: IssueOptions) {
const jobs = new Set(sorted.map(row => row.jobId).filter(validTraceId));
const repos = countBy(sorted, "repoId", validProjectId);
const users = countBy(sorted, "userId", validUserId);
const viewers = { signedIn: 0, visitors: 0, notRecorded: 0 };
for (const row of sorted) viewers[SIGNED_IN.has(String(row.viewer)) ? "signedIn" : row.viewer ? "visitors" : "notRecorded"]++;
// "visitor" is signed in without a role on the repository; "anonymous" has no session.
const viewers = { signedIn: 0, visitors: 0, anonymous: 0, notRecorded: 0 };
for (const row of sorted) viewers[ACCOUNT_ROLES.has(String(row.viewer)) ? "signedIn" : row.viewer === "visitor" ? "visitors" : row.viewer === "anonymous" ? "anonymous" : "notRecorded"]++;
const routeCounts = new Map<string, { route: string; method: string; count: number; last: string }>();
for (const row of sorted) {
const route = String(row.route || (row.queue ? `job ${row.queue}` : ""));