@debugkit/dashboard 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/client/assets/_authed-3se5Egqg.js +1 -0
  2. package/dist/client/assets/_authed-BfFWbTOO.js +1 -0
  3. package/dist/client/assets/app-code-BKWbvUMR.js +1 -0
  4. package/dist/client/assets/closed-issues-Cl-8l4oR.js +1 -0
  5. package/dist/client/assets/{copy-button-ORgLIh59.js → copy-button-BwRd5q7l.js} +1 -1
  6. package/dist/client/assets/customers-Cf-R8BOg.js +1 -0
  7. package/dist/client/assets/empty-state-njgr1sWu.js +7 -0
  8. package/dist/client/assets/endpoints-BMqAUNyE.js +1 -0
  9. package/dist/client/assets/events._eventId-CVRZJ-bU.js +2 -0
  10. package/dist/client/assets/exchange-view-DVwSLcXF.js +2 -0
  11. package/dist/client/assets/index-DEnCDILF.js +10 -0
  12. package/dist/client/assets/{invite._token-CxXek2SP.js → invite._token-CKAfd5iB.js} +1 -1
  13. package/dist/client/assets/issues._fingerprint-Cm72LNM_.js +55 -0
  14. package/dist/client/assets/login-BTxOhEbN.js +1 -0
  15. package/dist/client/assets/request-panel-DmtFRF8Z.js +1 -0
  16. package/dist/client/assets/services._service-CU1a45f3.js +1 -0
  17. package/dist/client/assets/{sessions._sessionId-3wNImMqM.js → sessions._sessionId-LRo3QNQP.js} +1 -1
  18. package/dist/client/assets/settings-Ctzvl2LL.js +1 -0
  19. package/dist/client/assets/src-BiKxgjA_.js +3 -0
  20. package/dist/client/assets/styles-Tcq0pvWj.css +2 -0
  21. package/dist/client/assets/{team-Bud2-07A.js → team-xlrjhEGp.js} +1 -1
  22. package/dist/client/assets/{timeline-BSDhQPpY.js → timeline-WXE49N62.js} +1 -1
  23. package/dist/client/assets/ui-DRjjeSWy.js +1 -0
  24. package/dist/client/assets/version-banner-BYe4PVzv.js +1 -0
  25. package/dist/server/assets/_authed-Bn-IktVS.js +120 -0
  26. package/dist/server/assets/_authed-RXh7GpoE.js +252 -0
  27. package/dist/server/assets/_tanstack-start-manifest_v-C4dQ3MxD.js +122 -0
  28. package/dist/server/assets/app-code-BQL_FcSx.js +212 -0
  29. package/dist/server/assets/app-name-BcbY1BZN.js +11 -0
  30. package/dist/server/assets/closed-issues-o9U80FXv.js +45 -0
  31. package/dist/server/assets/config-Bp8m0B8q.js +57 -0
  32. package/dist/server/assets/{customers-CvSLt_xV.js → customers-CD84Bz4P.js} +11 -6
  33. package/dist/server/assets/{demo-BRTkdmQJ.js → demo-D-o8m75S.js} +225 -8
  34. package/dist/server/assets/{dynamodb-B0V3ZO20.js → dynamodb-CcH0cp7R.js} +55 -2
  35. package/dist/server/assets/empty-state-wz34oAi8.js +163 -0
  36. package/dist/server/assets/endpoints-8N389Poe.js +248 -0
  37. package/dist/server/assets/{endpoints-mPQXpH8C.js → endpoints-C0Cxc_-x.js} +38 -36
  38. package/dist/server/assets/{events._eventId-pkQBQ9sL.js → events._eventId-BOHkNO5W.js} +90 -351
  39. package/dist/server/assets/exchange-view-DzoSBt_R.js +112 -0
  40. package/dist/server/assets/{firestore-Jd-LeWZI.js → firestore-DyvYMiz3.js} +13 -2
  41. package/dist/server/assets/{fns-Di0vMpkQ.js → fns-BcVGbSID.js} +22 -7
  42. package/dist/server/assets/fns-DE03YExD.js +831 -0
  43. package/dist/server/assets/{invite._token-LwWF5YxP.js → invite._token-DhlACkIe.js} +3 -3
  44. package/dist/server/assets/{issues._fingerprint-DAA0QCuA.js → issues._fingerprint-BBd-_Nn5.js} +400 -28
  45. package/dist/server/assets/{login-DqjCU4DJ.js → login-CbfdHJvg.js} +3 -3
  46. package/dist/server/assets/{memory-aqsrtEUn.js → memory-CZBUh1Zc.js} +129 -5
  47. package/dist/server/assets/{errors-C2KEDL7l.js → queries-wha4cZbw.js} +1442 -129
  48. package/dist/server/assets/request-panel-DpCSwl2q.js +162 -0
  49. package/dist/server/assets/{router-C0Dauj2C.js → router-BXkzR89j.js} +197 -91
  50. package/dist/server/assets/services._service-DWjFFGON.js +309 -0
  51. package/dist/server/assets/{sessions._sessionId-D7JPV0M4.js → sessions._sessionId-DDspiPTe.js} +2 -2
  52. package/dist/server/assets/{settings-Drjd64d7.js → settings-DCLIaZ_p.js} +201 -24
  53. package/dist/server/assets/{src-C4fNgijW.js → src-B2GKPQyN.js} +1 -1
  54. package/dist/server/assets/{team-D7iXYnSE.js → team-jd_TmWP4.js} +3 -3
  55. package/dist/server/assets/ui-C3pl0edn.js +302 -0
  56. package/dist/server/assets/version-banner-BX34ijG5.js +106 -0
  57. package/dist/server/assets/versions-YI_zK1ql.js +58 -0
  58. package/dist/server/assets/warm-C3GbXP1_.js +16 -0
  59. package/dist/server/server.js +40 -28
  60. package/package.json +4 -4
  61. package/dist/client/assets/_authed-CNObwuZh.js +0 -7
  62. package/dist/client/assets/_authed-CuP-He8G.js +0 -1
  63. package/dist/client/assets/charts-CUvev8lV.js +0 -55
  64. package/dist/client/assets/customers-DTMEprFQ.js +0 -1
  65. package/dist/client/assets/endpoints-lMSO2CdM.js +0 -1
  66. package/dist/client/assets/events._eventId-bWag-i8J.js +0 -3
  67. package/dist/client/assets/index-BNpacHyi.js +0 -10
  68. package/dist/client/assets/issues._fingerprint-BQr85TVY.js +0 -1
  69. package/dist/client/assets/login-Dlk3GyyC.js +0 -1
  70. package/dist/client/assets/settings-CzbEYB7k.js +0 -1
  71. package/dist/client/assets/src-Dq5mIUf0.js +0 -3
  72. package/dist/client/assets/styles-DPsgRH7g.css +0 -2
  73. package/dist/client/assets/ui-CEv2y56s.js +0 -1
  74. package/dist/server/assets/_authed-DkkRwdZl.js +0 -87
  75. package/dist/server/assets/_authed-DsB8kjZB.js +0 -902
  76. package/dist/server/assets/_tanstack-start-manifest_v-D1_ErrJK.js +0 -97
  77. package/dist/server/assets/charts-DzTVqJ8z.js +0 -238
  78. package/dist/server/assets/fns-B3PHbFwV.js +0 -1295
  79. package/dist/server/assets/ui-B_XHlLUQ.js +0 -193
@@ -1,5 +1,5 @@
1
- import { l as isRegression, r as coalesceRollups } from "./memory-aqsrtEUn.js";
2
- import "./src-C4fNgijW.js";
1
+ import { b as isRegression, o as versionKey, s as coalesceRollups } from "./memory-CZBUh1Zc.js";
2
+ import "./src-B2GKPQyN.js";
3
3
  import { BatchWriteCommand, GetCommand, PutCommand, QueryCommand, UpdateCommand } from "@aws-sdk/lib-dynamodb";
4
4
  // ../../packages/adapters/src/dynamodb.ts
5
5
  /**
@@ -15,6 +15,7 @@ import { BatchWriteCommand, GetCommand, PutCommand, QueryCommand, UpdateCommand
15
15
  * APP#{app}#USEREV#id#{userId} | {ts}#{id} StoredEvent (by customer number, user.id)
16
16
  * APP#{app}#USEREV#anonymousId#{anonymousId} | {ts}#{id} StoredEvent (by install id)
17
17
  * APP#{app}#SETTINGS | app AppSettings
18
+ * APP#{app}#VERSIONS | v Versions (sdk, sdkKey, sdkSeenAt, ingest, ingestAt)
18
19
  * APP#{app}#USERS#{scope} | {member} { lastDay } (hashed ids; for "users affected")
19
20
  *
20
21
  * TEAM | M#{email} TeamMember (dashboard logins)
@@ -126,6 +127,58 @@ var DynamoStore = class {
126
127
  }
127
128
  }));
128
129
  }
130
+ /**
131
+ * The SDK version only moves forward: a conditional update on its sortable key (versionKey), so two
132
+ * ingests seeing different SDKs keep the newer, and the same one again moves its seenAt on. The
133
+ * ingest version is whoever wrote last.
134
+ */
135
+ async recordVersions(app, seen) {
136
+ const Key = {
137
+ pk: `APP#${app}#VERSIONS`,
138
+ sk: "v"
139
+ };
140
+ const key = versionKey(seen.sdk);
141
+ await Promise.all([key && this.doc.send(new UpdateCommand({
142
+ TableName: this.table,
143
+ Key,
144
+ UpdateExpression: "SET sdk = :v, sdkKey = :k, sdkSeenAt = :at",
145
+ ConditionExpression: "attribute_not_exists(sdkKey) OR sdkKey <= :k",
146
+ ExpressionAttributeValues: {
147
+ ":v": seen.sdk,
148
+ ":k": key,
149
+ ":at": seen.at
150
+ }
151
+ })).catch((e) => {
152
+ if (e.name !== "ConditionalCheckFailedException") throw e;
153
+ }), this.doc.send(new UpdateCommand({
154
+ TableName: this.table,
155
+ Key,
156
+ UpdateExpression: "SET ingest = :v, ingestAt = :at",
157
+ ExpressionAttributeValues: {
158
+ ":v": seen.ingest,
159
+ ":at": seen.at
160
+ }
161
+ }))]);
162
+ }
163
+ async getVersions(app) {
164
+ const i = (await this.doc.send(new GetCommand({
165
+ TableName: this.table,
166
+ Key: {
167
+ pk: `APP#${app}#VERSIONS`,
168
+ sk: "v"
169
+ }
170
+ }))).Item;
171
+ return {
172
+ ...i?.sdk && i.sdkSeenAt ? { sdk: {
173
+ version: i.sdk,
174
+ seenAt: i.sdkSeenAt
175
+ } } : {},
176
+ ...i?.ingest && i.ingestAt ? { ingest: {
177
+ version: i.ingest,
178
+ at: i.ingestAt
179
+ } } : {}
180
+ };
181
+ }
129
182
  async writeEvents(events, opts = {}) {
130
183
  const days = opts.retentionDays ?? this.opts.retentionDays ?? 30;
131
184
  const ttl = (e) => Math.floor(Date.parse(e.receivedAt) / 1e3) + days * 86400;
@@ -0,0 +1,163 @@
1
+ import { useEffect } from "react";
2
+ import { useRouter } from "@tanstack/react-router";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ // src/components/empty-state.tsx
5
+ var WHAT_YOU_WILL_SEE = [
6
+ {
7
+ title: "A health wall",
8
+ when: "after the first request",
9
+ detail: "Every service the app calls, and the app's own code, as a box in red, orange, yellow, grey or green, worst first. Click one for what's failing, how often, and why."
10
+ },
11
+ {
12
+ title: "A written summary",
13
+ when: "after the first error",
14
+ detail: "How many errors in the last 24 hours, the worst part of the app, the top issue and the release that's struggling, in plain sentences."
15
+ },
16
+ {
17
+ title: "Incidents",
18
+ when: "when several errors share a cause",
19
+ detail: "Issues that failed together for the same reason, like every request failing right after the app reopens, shown as one problem with the issues inside it."
20
+ },
21
+ {
22
+ title: "Issues by severity",
23
+ when: "after the first error",
24
+ detail: "Errors grouped by cause. Severity comes from how often each happened in the last 24 hours. Open one for the stack trace and the steps that led to it."
25
+ },
26
+ {
27
+ title: "Release health",
28
+ when: "as soon as the app starts",
29
+ detail: "Every app launch is a session. You'll see the share of sessions per version that ran without a crash or an unhandled error."
30
+ },
31
+ {
32
+ title: "Failing endpoints",
33
+ when: "after the first failed request",
34
+ detail: "Requests that timed out, failed or returned 5xx, captured from fetch and XHR without any code from you."
35
+ },
36
+ {
37
+ title: "Where the app is failing",
38
+ when: "once you tag flows",
39
+ detail: "Errors by flow, like auth.login or checkout.payment. Wrap a step in deBug.track() and each flow also gets a failure rate."
40
+ },
41
+ {
42
+ title: "Breakdowns",
43
+ when: "after the first error",
44
+ detail: "Errors split by OS, app version and device model, so you can see who is affected."
45
+ }
46
+ ];
47
+ /** What a new dashboard shows until the first event arrives. It reloads itself every 5 s. */
48
+ function EmptyState() {
49
+ const router = useRouter();
50
+ useEffect(() => {
51
+ const t = setInterval(() => void router.invalidate(), 5e3);
52
+ return () => clearInterval(t);
53
+ }, [router]);
54
+ return /* @__PURE__ */ jsxs("main", {
55
+ className: "mx-auto max-w-4xl space-y-6 px-4 py-10 sm:px-6",
56
+ children: [
57
+ /* @__PURE__ */ jsxs("div", { children: [
58
+ /* @__PURE__ */ jsx("p", {
59
+ className: "text-xs uppercase tracking-wide text-muted",
60
+ children: "Connected · waiting for the first event"
61
+ }),
62
+ /* @__PURE__ */ jsx("h1", {
63
+ className: "mt-1 text-2xl font-semibold tracking-tight",
64
+ children: "Your dashboard is ready, and empty for now."
65
+ }),
66
+ /* @__PURE__ */ jsxs("p", {
67
+ className: "mt-2 max-w-2xl text-sm text-muted",
68
+ children: [
69
+ "Nothing has arrived yet. Run your app with the SDK initialised, or send a test event with ",
70
+ /* @__PURE__ */ jsx("code", { children: "npx debugkit test" }),
71
+ " (or ",
72
+ /* @__PURE__ */ jsx("code", { children: "npx @debugkit/cli test" }),
73
+ "). This page fills in on its own."
74
+ ]
75
+ })
76
+ ] }),
77
+ /* @__PURE__ */ jsxs("section", {
78
+ "aria-labelledby": "see-h",
79
+ className: "rounded-xl border border-line bg-panel p-4 sm:p-5",
80
+ children: [/* @__PURE__ */ jsx("h2", {
81
+ id: "see-h",
82
+ className: "text-sm font-semibold",
83
+ children: "What you'll see here"
84
+ }), /* @__PURE__ */ jsx("ul", {
85
+ className: "mt-3 grid gap-3 sm:grid-cols-2",
86
+ children: WHAT_YOU_WILL_SEE.map((w) => /* @__PURE__ */ jsxs("li", {
87
+ className: "rounded-lg border border-line p-3",
88
+ children: [/* @__PURE__ */ jsxs("div", {
89
+ className: "flex flex-wrap items-baseline justify-between gap-2",
90
+ children: [/* @__PURE__ */ jsx("span", {
91
+ className: "font-medium",
92
+ children: w.title
93
+ }), /* @__PURE__ */ jsx("span", {
94
+ className: "text-[11px] uppercase tracking-wide text-muted",
95
+ children: w.when
96
+ })]
97
+ }), /* @__PURE__ */ jsx("p", {
98
+ className: "mt-1 text-sm text-ink/80",
99
+ children: w.detail
100
+ })]
101
+ }, w.title))
102
+ })]
103
+ }),
104
+ /* @__PURE__ */ jsxs("div", {
105
+ className: "grid gap-4 md:grid-cols-2",
106
+ children: [/* @__PURE__ */ jsxs("section", {
107
+ "aria-labelledby": "auto-h",
108
+ className: "rounded-xl border border-line bg-panel p-4 sm:p-5",
109
+ children: [
110
+ /* @__PURE__ */ jsx("h2", {
111
+ id: "auto-h",
112
+ className: "text-sm font-semibold",
113
+ children: "Recorded automatically"
114
+ }),
115
+ /* @__PURE__ */ jsxs("p", {
116
+ className: "mt-1 text-xs text-muted",
117
+ children: [
118
+ "Once ",
119
+ /* @__PURE__ */ jsx("code", { children: "init()" }),
120
+ " runs, with no other code."
121
+ ]
122
+ }),
123
+ /* @__PURE__ */ jsxs("ul", {
124
+ className: "mt-3 list-disc space-y-1 pl-5 text-sm",
125
+ children: [
126
+ /* @__PURE__ */ jsx("li", { children: "Crashes and unhandled promise rejections" }),
127
+ /* @__PURE__ */ jsx("li", { children: "Failed, timed-out and 5xx requests, with the code that made them" }),
128
+ /* @__PURE__ */ jsx("li", { children: "Sessions, for crash-free rates per release" }),
129
+ /* @__PURE__ */ jsx("li", { children: "Screens visited, buttons clicked, console warnings, app backgrounded or offline" }),
130
+ /* @__PURE__ */ jsx("li", { children: "Device, OS, app version and network on every event" })
131
+ ]
132
+ })
133
+ ]
134
+ }), /* @__PURE__ */ jsxs("section", {
135
+ "aria-labelledby": "manual-h",
136
+ className: "rounded-xl border border-line bg-panel p-4 sm:p-5",
137
+ children: [
138
+ /* @__PURE__ */ jsx("h2", {
139
+ id: "manual-h",
140
+ className: "text-sm font-semibold",
141
+ children: "What you add"
142
+ }),
143
+ /* @__PURE__ */ jsx("p", {
144
+ className: "mt-1 text-xs text-muted",
145
+ children: "Only what the app can't know on its own."
146
+ }),
147
+ /* @__PURE__ */ jsx("pre", {
148
+ className: "mt-3 overflow-x-auto rounded-md bg-panel-2 p-3 text-xs leading-relaxed",
149
+ children: `// in a try/catch you already have
150
+ catch (err) {
151
+ deBug.error(err, { flow: "checkout.payment", step: "charge" });
152
+ }
153
+
154
+ // success or failure of a step, plus the error
155
+ await deBug.track("auth.login", "submit_otp", () => verifyOtp(code));`
156
+ })
157
+ ]
158
+ })]
159
+ })
160
+ ]
161
+ });
162
+ }
163
+ export { EmptyState as t };
@@ -0,0 +1,248 @@
1
+ import { I as OUTAGE, K as servicesOf, V as failing, a as retentionFor, i as endpointTimings, j as isRequestCategory, l as failedRequest, o as resolveRange, s as apiCallOf, u as timelineOf } from "./queries-wha4cZbw.js";
2
+ import { A as hostNameFor, N as nameUrlsIn, S as isTestIssue, k as hostKindOf, y as isOfflineIssue } from "./memory-CZBUh1Zc.js";
3
+ var ISSUE_READ_LIMIT = 500;
4
+ /**
5
+ * The key an endpoint counts under: "<METHOD> <url>" as the SDK's request summaries name it, with
6
+ * the method in capitals and cut where the SDK cuts the summary's key.
7
+ */
8
+ function endpointKey(method, url) {
9
+ return `${method.toUpperCase()} ${url}`.slice(0, 300);
10
+ }
11
+ /**
12
+ * A stored error that is a failed API call: the SDK's request on it, a request category label, or
13
+ * (a failure the app reported itself) a failed call as its last breadcrumb, just before it.
14
+ */
15
+ function isNetworkIssue(i) {
16
+ const e = i.lastEvent.event;
17
+ if (e.type !== "error") return false;
18
+ if (e.request || i.lastEvent.labels?.category && isRequestCategory(i.lastEvent.labels.category)) return true;
19
+ const last = e.breadcrumbs?.[e.breadcrumbs.length - 1];
20
+ return !!last && !!apiCallOf(last)?.failed && Math.abs(Date.parse(e.ts) - Date.parse(last.ts)) <= 2e3;
21
+ }
22
+ /**
23
+ * The failed call an error describes, and the endpoint key it counts under: the SDK's request, or
24
+ * for a failure the app reported itself, the request-summary key with the same method and path.
25
+ */
26
+ function failureOf(e, hosts = [], keys = []) {
27
+ if (e.event.type !== "error") return void 0;
28
+ const req = e.event.request;
29
+ const call = failedRequest(req, timelineOf(e.event.breadcrumbs, hosts), hosts);
30
+ if (req) return {
31
+ endpoint: endpointKey(req.method, req.url),
32
+ call,
33
+ e
34
+ };
35
+ if (!call?.path) return void 0;
36
+ const known = keys.find((k) => sameCall(k, call.method, call.path));
37
+ if (known) return {
38
+ endpoint: known,
39
+ call,
40
+ e
41
+ };
42
+ return {
43
+ endpoint: [
44
+ call.method,
45
+ call.service,
46
+ call.path
47
+ ].filter(Boolean).join(" "),
48
+ own: {
49
+ method: call.method,
50
+ path: call.path
51
+ },
52
+ call,
53
+ e
54
+ };
55
+ }
56
+ /** Whether a request-summary key ("<METHOD> <url>") is the call the app names by method and path. */
57
+ function sameCall(key, method, path) {
58
+ const [m, ...rest] = key.split(" ");
59
+ const url = rest.join(" ").split(/[?#]/)[0];
60
+ return (!method || m === method.toUpperCase()) && (url === path || url.endsWith(path.startsWith("/") ? path : `/${path}`));
61
+ }
62
+ /** "503", or the outcome or kind of failure when there was no answer. */
63
+ function statusOf(f) {
64
+ const c = f.call;
65
+ const status = (f.e.event.type === "error" ? f.e.event.request?.status : void 0) ?? c?.status;
66
+ if (status !== void 0) return String(status);
67
+ const timedOut = f.e.event.type === "error" && /timed out|timeout/i.test(f.e.event.error.message);
68
+ return c?.outcome ?? c?.errorKind ?? (timedOut ? "timed out" : "no answer");
69
+ }
70
+ function counts(values) {
71
+ const m = /* @__PURE__ */ new Map();
72
+ for (const v of values) if (v) m.set(v, (m.get(v) ?? 0) + 1);
73
+ return [...m.entries()].map(([key, count]) => ({
74
+ key,
75
+ count
76
+ })).sort((a, b) => b.count - a.count || a.key.localeCompare(b.key));
77
+ }
78
+ async function buildEndpoints(store, appParam, now = Date.now(), opts = {}) {
79
+ const apps = await store.listApps();
80
+ const app = appParam && apps.includes(appParam) ? appParam : apps[0];
81
+ if (!app) return null;
82
+ const range = resolveRange(opts.range ?? {}, now);
83
+ const [requestRows, latencyRows, issues, settings, retention] = await Promise.all([
84
+ store.getRollups(app, "requests", range.from, range.to),
85
+ store.getRollups(app, "latency", range.from, range.to),
86
+ store.listIssues(app, { limit: ISSUE_READ_LIMIT }),
87
+ store.getSettings(app).catch(() => null),
88
+ retentionFor(store, app, opts.retentionDays, now)
89
+ ]);
90
+ const hosts = settings?.hosts ?? [];
91
+ const network = issues.filter((i) => isNetworkIssue(i) && !isTestIssue(i) && !isOfflineIssue(i) && i.lastSeen.slice(0, 10) >= range.from).sort((a, b) => b.lastSeen.localeCompare(a.lastSeen));
92
+ const read = network.slice(0, 100);
93
+ const perIssue = await Promise.all(read.map((i) => store.listIssueEvents(app, i.fingerprint, { limit: 200 })));
94
+ const events = perIssue.flat();
95
+ const inRange = (e) => e.day >= range.from && e.day <= range.to;
96
+ const capped = perIssue.some((list) => list.length >= 200 && inRange(list[list.length - 1]));
97
+ const timings = /* @__PURE__ */ new Map();
98
+ for (const t of endpointTimings(requestRows, latencyRows, hosts)) {
99
+ const [m, ...rest] = t.endpoint.split(" ");
100
+ timings.set(endpointKey(m, rest.join(" ")), t);
101
+ }
102
+ const today = new Date(now).toISOString().slice(0, 10);
103
+ const todays = /* @__PURE__ */ new Map();
104
+ for (const r of requestRows) {
105
+ if (r.day !== today) continue;
106
+ const [m, ...rest] = r.key.split(" ");
107
+ const k = endpointKey(m, rest.join(" "));
108
+ const t = todays.get(k) ?? {
109
+ calls: 0,
110
+ failed: 0
111
+ };
112
+ todays.set(k, {
113
+ calls: t.calls + r.events,
114
+ failed: t.failed + r.errors
115
+ });
116
+ }
117
+ const failures = events.filter(inRange).map((e) => failureOf(e, hosts, [...timings.keys()])).filter((f) => !!f);
118
+ const byEndpoint = /* @__PURE__ */ new Map();
119
+ for (const f of failures) byEndpoint.set(f.endpoint, [...byEndpoint.get(f.endpoint) ?? [], f]);
120
+ const named = events.flatMap((e) => e.event.type === "error" ? e.event.breadcrumbs ?? [] : []).map((b) => apiCallOf(b, hosts)).filter((c) => !!c?.service && !!c.path);
121
+ const serviceFor = (endpoint) => named.find((c) => sameCall(endpoint, c.method, c.path));
122
+ const byFingerprint = new Map(issues.map((i) => [i.fingerprint, {
123
+ ...i,
124
+ title: nameUrlsIn(i.title, hosts)
125
+ }]));
126
+ const rowFor = (endpoint) => {
127
+ const fs = byEndpoint.get(endpoint) ?? [];
128
+ const t = timings.get(endpoint);
129
+ const own = fs.find((f) => f.call?.service)?.call ?? serviceFor(endpoint);
130
+ const fallback = fs.find((f) => f.own)?.own;
131
+ const [first, ...rest] = endpoint.split(" ");
132
+ const method = fallback ? fallback.method : first;
133
+ const url = fallback ? fallback.path : rest.join(" ");
134
+ const host = hostNameFor(url, hosts);
135
+ const kind = hostKindOf(host?.host);
136
+ return {
137
+ endpoint,
138
+ service: own?.service ?? host?.host.name,
139
+ ...kind ? { kind } : {},
140
+ ...kind === "upstream" && host?.host.provider ? { provider: host.host.provider } : {},
141
+ down: downOf(fs, now),
142
+ ...todays.has(endpoint) ? { today: todays.get(endpoint) } : {},
143
+ method: own?.method ?? method,
144
+ path: host ? host.rest || "/" : own?.path ?? url,
145
+ calls: t?.requests ?? null,
146
+ failedCalls: t?.failed ?? null,
147
+ failureRate: t ? t.errorRate : null,
148
+ p50: t?.p50 ?? null,
149
+ p95: t?.p95 ?? null,
150
+ failures: fs.length,
151
+ statuses: counts(fs.map(statusOf)),
152
+ backendCodes: counts(fs.map((f) => f.call?.backendCode)),
153
+ backendMessages: counts(fs.map((f) => f.call?.backendTitle)),
154
+ problems: problemsOf(fs, byFingerprint),
155
+ lastAnswer: lastAnswerOf(fs),
156
+ lastFailure: fs.map((f) => f.e.event.ts).sort().pop()
157
+ };
158
+ };
159
+ const endpoints = [.../* @__PURE__ */ new Set([...timings.keys(), ...byEndpoint.keys()])].map(rowFor).sort((a, b) => failing(b) - failing(a) || (b.calls ?? 0) - (a.calls ?? 0));
160
+ const chosen = opts.endpoint ? endpoints.find((r) => r.endpoint === opts.endpoint) : void 0;
161
+ const selected = chosen && {
162
+ endpoint: chosen,
163
+ failures: (byEndpoint.get(chosen.endpoint) ?? []).sort((a, b) => Date.parse(b.e.event.ts) - Date.parse(a.e.event.ts)).slice(0, 50).map((f) => ({
164
+ eventId: f.e.event.id,
165
+ fingerprint: f.e.fingerprint,
166
+ ts: f.e.event.ts,
167
+ status: statusOf(f),
168
+ durationMs: f.call?.durationMs,
169
+ errorKind: f.call?.errorKind,
170
+ backendCode: f.call?.backendCode,
171
+ backendTitle: f.call?.backendTitle,
172
+ traceId: f.call?.traceId,
173
+ sessionId: f.e.sessionId,
174
+ userId: f.e.user?.id
175
+ }))
176
+ };
177
+ return {
178
+ app,
179
+ generatedAt: new Date(now).toISOString(),
180
+ apps,
181
+ range,
182
+ retention,
183
+ services: servicesOf(endpoints),
184
+ endpoints,
185
+ selected,
186
+ missing: opts.endpoint && !chosen ? opts.endpoint : void 0,
187
+ truncated: issues.length >= ISSUE_READ_LIMIT || network.length > read.length || capped
188
+ };
189
+ }
190
+ /** The statuses that mean the server never answered. Anything else the app reports (sessionExpired, schemaError, …) isn't the server being down. */
191
+ var NO_ANSWER = /* @__PURE__ */ new Set([
192
+ "no answer",
193
+ "timed out",
194
+ "timeout",
195
+ "unreachable"
196
+ ]);
197
+ /** No answer at all (unreachable, timed out) or a server error: the server, not the request, failed. */
198
+ function isServerDown(status) {
199
+ const n = Number(status);
200
+ return Number.isInteger(n) ? n >= 500 : NO_ANSWER.has(status);
201
+ }
202
+ /** Recent no-answer and 5xx failures on an endpoint: see EndpointHealth.down. */
203
+ function downOf(fs, now) {
204
+ const recent = fs.filter((f) => {
205
+ const age = now - Date.parse(f.e.event.ts);
206
+ return age >= 0 && age <= OUTAGE.windowMs && isServerDown(statusOf(f));
207
+ });
208
+ if (!recent.length) return void 0;
209
+ return {
210
+ who: [...new Set(recent.map((f) => f.e.user?.id ?? f.e.user?.anonymousId ?? f.e.sessionId))],
211
+ failures: recent.length,
212
+ statuses: counts(recent.map(statusOf)),
213
+ last: recent.map((f) => f.e.event.ts).sort().pop()
214
+ };
215
+ }
216
+ /** How much of a server's answer an endpoint row carries. */
217
+ var ANSWER_CHARS = 1500;
218
+ /** The newest failure the server answered, with what it said. */
219
+ function lastAnswerOf(fs) {
220
+ const answered = fs.filter((f) => f.e.event.type === "error" && f.e.event.response).sort((a, b) => b.e.event.ts.localeCompare(a.e.event.ts))[0];
221
+ if (!answered || answered.e.event.type !== "error") return void 0;
222
+ const r = answered.e.event.response;
223
+ const body = r.body && r.body.length > 1500 ? `${r.body.slice(0, ANSWER_CHARS)}…` : r.body;
224
+ return {
225
+ status: r.status,
226
+ body,
227
+ ts: answered.e.event.ts,
228
+ eventId: answered.e.event.id,
229
+ fingerprint: answered.e.fingerprint
230
+ };
231
+ }
232
+ /** An endpoint's failures grouped by issue, most first. */
233
+ function problemsOf(fs, issues) {
234
+ const by = /* @__PURE__ */ new Map();
235
+ for (const f of fs) if (f.e.fingerprint) by.set(f.e.fingerprint, [...by.get(f.e.fingerprint) ?? [], f]);
236
+ return [...by.entries()].map(([fingerprint, list]) => ({
237
+ fingerprint,
238
+ title: issues.get(fingerprint)?.title ?? fingerprint,
239
+ issueStatus: issues.get(fingerprint)?.status ?? "open",
240
+ resolvedIn: issues.get(fingerprint)?.resolvedIn,
241
+ count: list.length,
242
+ status: counts(list.map(statusOf))[0]?.key ?? "no answer",
243
+ lastSeen: list.map((f) => f.e.event.ts).sort().pop(),
244
+ platforms: counts(list.map((f) => f.e.context.os.name)).map((c) => c.key),
245
+ versions: counts(list.map((f) => f.e.context.app.version)).map((c) => c.key)
246
+ })).sort((a, b) => b.count - a.count || b.lastSeen.localeCompare(a.lastSeen));
247
+ }
248
+ export { buildEndpoints as t };
@@ -1,7 +1,8 @@
1
1
  import { n as RetentionNote, t as RangePicker } from "./range-picker-0zbSGr3Z.js";
2
2
  import { a as joined, i as clock } from "./timeline-MDRNDhiA.js";
3
- import { l as timeAgo, t as Card } from "./ui-B_XHlLUQ.js";
4
- import { c as Route } from "./router-C0Dauj2C.js";
3
+ import { a as HealthBox, n as Card, p as timeAgo, t as AppOptions } from "./ui-C3pl0edn.js";
4
+ import { G as serviceTile, R as byHealth } from "./queries-wha4cZbw.js";
5
+ import { l as Route } from "./router-BXkzR89j.js";
5
6
  import { Link, useNavigate } from "@tanstack/react-router";
6
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
8
  // src/routes/_authed/endpoints.tsx?tsr-split=component
@@ -12,7 +13,8 @@ var SORTS = {
12
13
  };
13
14
  function EndpointsPage() {
14
15
  const report = Route.useLoaderData();
15
- const { sort = "failing" } = Route.useSearch();
16
+ const search = Route.useSearch();
17
+ const { sort = "failing" } = search;
16
18
  const navigate = useNavigate({ from: Route.fullPath });
17
19
  if (!report) return /* @__PURE__ */ jsx("main", {
18
20
  className: "mx-auto max-w-3xl px-4 py-10 sm:px-6",
@@ -56,7 +58,10 @@ function EndpointsPage() {
56
58
  endpoint: void 0
57
59
  }) }),
58
60
  className: "rounded-md border border-line bg-panel px-2 py-1.5 text-sm",
59
- children: report.apps.map((a) => /* @__PURE__ */ jsx("option", { children: a }, a))
61
+ children: /* @__PURE__ */ jsx(AppOptions, {
62
+ apps: report.apps,
63
+ names: report.names
64
+ })
60
65
  })]
61
66
  })]
62
67
  }),
@@ -88,7 +93,17 @@ function EndpointsPage() {
88
93
  range.label,
89
94
  ". Calls are counted when the SDK's network capture is on, and failures when they're stored as errors."
90
95
  ]
91
- }) : /* @__PURE__ */ jsxs(Fragment, { children: [services.length > 1 && /* @__PURE__ */ jsx(Services, { rows: services }), /* @__PURE__ */ jsxs(Card, {
96
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [services.length > 0 && /* @__PURE__ */ jsx(Services, {
97
+ rows: services,
98
+ endpoints: report.endpoints,
99
+ keep: {
100
+ app: report.app,
101
+ range: search.range,
102
+ from: search.from,
103
+ to: search.to
104
+ },
105
+ now: Date.parse(report.generatedAt)
106
+ }), /* @__PURE__ */ jsxs(Card, {
92
107
  title: `${endpoints.length} endpoint${endpoints.length === 1 ? "" : "s"}`,
93
108
  subtitle: "Calls, failure rate and timings count every call the SDK saw. Statuses and backend codes count the stored failures, which the SDK samples.",
94
109
  right: /* @__PURE__ */ jsx("span", {
@@ -280,41 +295,28 @@ function EndpointDetail({ app, row, failures }) {
280
295
  })]
281
296
  });
282
297
  }
283
- /** Endpoints added up per backend service: which one is failing or slow, at a glance. */
284
- function Services({ rows }) {
298
+ /** Each backend service as a box in its level's colour, worst first; a box opens that service. */
299
+ function Services({ rows, endpoints, keep, now }) {
300
+ const tiles = rows.map((r) => serviceTile(r, endpoints, now)).sort(byHealth);
285
301
  return /* @__PURE__ */ jsxs(Card, {
286
302
  title: "By service",
287
- subtitle: "Each backend service's endpoints added up. The slowest p95 is its slowest endpoint's.",
303
+ subtitle: "Coloured by how each is doing, worst first. Click one for what's failing, how often, and why.",
288
304
  children: [/* @__PURE__ */ jsx("ul", {
289
305
  className: "grid gap-2 sm:grid-cols-2 lg:grid-cols-3",
290
- children: rows.map((r) => /* @__PURE__ */ jsxs("li", {
291
- className: "rounded-lg border border-line px-3 py-2 text-sm",
292
- children: [/* @__PURE__ */ jsxs("div", {
293
- className: "flex items-baseline justify-between gap-2",
294
- children: [/* @__PURE__ */ jsx("span", {
295
- className: r.service ? "font-medium" : "text-muted",
296
- children: r.service ?? "Unnamed hosts"
297
- }), /* @__PURE__ */ jsxs("span", {
298
- className: `tabular ${r.failureRate !== null && r.failureRate >= .05 ? "font-semibold text-sev-critical" : "text-muted"}`,
299
- children: [rate(r.failureRate), " failed"]
300
- })]
301
- }), /* @__PURE__ */ jsxs("div", {
302
- className: "tabular mt-0.5 text-xs text-muted",
303
- children: [
304
- count(r.calls),
305
- " calls · ",
306
- r.endpoints,
307
- " endpoint",
308
- r.endpoints === 1 ? "" : "s",
309
- " · slowest p95 ",
310
- /* @__PURE__ */ jsx("span", {
311
- className: r.worstP95 !== null && r.worstP95 >= 3e3 ? "font-semibold text-sev-high" : "",
312
- children: ms(r.worstP95)
313
- }),
314
- r.failures > 0 && ` · ${r.failures} stored failure${r.failures === 1 ? "" : "s"}`
315
- ]
316
- })]
317
- }, r.service ?? ""))
306
+ children: tiles.map((t) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(HealthBox, {
307
+ level: t.level,
308
+ name: t.name,
309
+ headline: t.headline,
310
+ measure: t.measure,
311
+ live: t.live,
312
+ lastFailure: t.lastFailure,
313
+ link: {
314
+ to: "/services/$service",
315
+ params: { service: t.key },
316
+ search: keep
317
+ },
318
+ now
319
+ }) }, t.key))
318
320
  }), rows.some((r) => !r.service) && /* @__PURE__ */ jsx("p", {
319
321
  className: "mt-2 text-xs text-muted",
320
322
  children: "Name hosts in Settings, or set the SDK's network.baseUrls, to group unnamed ones."