GeezerVison is showing github.com — fix(cli): use singular counts in one-span trace summaries (#43231) · patroza/t3code@e380d41
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/cli/trace.test.ts +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,3 +140,26 @@ it("formats large summaries without overflowing the call stack", () => { | 140 | 140 | "long-span-name 1 1.0 1ms 1ms 1ms 0 0", | 141 | 141 | ); | 142 | 142 | }); | | 143 | + | | 144 | +it("uses singular nouns only for counts of one", () => { | | 145 | + const summarize = (lines: ReadonlyArray<string>) => { | | 146 | + const summarizer = makeTraceSpanSummary(); | | 147 | + lines.forEach(summarizer.addLine); | | 148 | + return formatTraceSummary(summarizer.finish(), 0).split("\n"); | | 149 | + }; | | 150 | + const one = summarize([span("a", 1, MINUTE_MS), "{not json"]); | | 151 | + const two = summarize([span("a", 1, MINUTE_MS), span("b", 1, MINUTE_MS), "x", "y"]); | | 152 | + | | 153 | + assert.deepStrictEqual( | | 154 | + [one[0]?.split(" ended")[0], one[1], one.at(-1)], | | 155 | + ["1 span", "Skipped 1 line that is not a span.", "1 more span name. Use --limit to show more."], | | 156 | + ); | | 157 | + assert.deepStrictEqual( | | 158 | + [two[0]?.split(" ended")[0], two[1], two.at(-1)], | | 159 | + [ | | 160 | + "2 spans", | | 161 | + "Skipped 2 lines that are not spans.", | | 162 | + "2 more span names. Use --limit to show more.", | | 163 | + ], | | 164 | + ); | | 165 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/cli/trace.ts +12-7Lines changed: 12 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -122,6 +122,9 @@ export function makeTraceSpanSummary(window?: { nowMs: number; duration: Duratio | 122 | 122 | return { addLine, finish }; | 123 | 123 | } | 124 | 124 |
| | 125 | +const formatSkippedLines = (count: number) => | | 126 | + count === 1 ? "Skipped 1 line that is not a span." : `Skipped ${count} lines that are not spans.`; | | 127 | + | 125 | 128 | const formatMs = (ms: number) => | 126 | 129 | Math.round(ms) < 1_000 ? `${Math.round(ms)}ms` : `${Math.round(ms / 100) / 10}s`; | 127 | 130 |
| @@ -151,11 +154,10 @@ export function formatTraceSummary( | 151 | 154 | table.reduce((max, row) => Math.max(max, row[column]!.length), 0), | 152 | 155 | ); | 153 | 156 | const formatIso = (ms: number) => DateTime.formatIso(DateTime.makeUnsafe(ms)); | | 157 | + const hiddenCount = summary.spans.length - limit; | 154 | 158 | return [ | 155 | | - `${summary.spanCount} spans ended from ${formatIso(summary.firstEndMs)} to ${formatIso(summary.lastEndMs)} (${summary.minutes.toFixed(1).replace(/\.0+$/, "")} min).`, | 156 | | - ...(summary.skippedLineCount > 0 | 157 | | - ? [`Skipped ${summary.skippedLineCount} lines that are not spans.`] | 158 | | - : []), | | 159 | + `${summary.spanCount} ${summary.spanCount === 1 ? "span" : "spans"} ended from ${formatIso(summary.firstEndMs)} to ${formatIso(summary.lastEndMs)} (${summary.minutes.toFixed(1).replace(/\.0+$/, "")} min).`, | | 160 | + ...(summary.skippedLineCount > 0 ? [formatSkippedLines(summary.skippedLineCount)] : []), | 159 | 161 | "", | 160 | 162 | ...table.map((row) => | 161 | 163 | row | @@ -164,8 +166,11 @@ export function formatTraceSummary( | 164 | 166 | ) | 165 | 167 | .join(" "), | 166 | 168 | ), | 167 | | - ...(summary.spans.length > limit | 168 | | - ? ["", `${summary.spans.length - limit} more span names. Use --limit to show more.`] | | 169 | + ...(hiddenCount > 0 | | 170 | + ? [ | | 171 | + "", | | 172 | + `${hiddenCount} more ${hiddenCount === 1 ? "span name" : "span names"}. Use --limit to show more.`, | | 173 | + ] | 169 | 174 | : []), | 170 | 175 | ].join("\n"); | 171 | 176 | } | @@ -207,7 +212,7 @@ const traceSummaryCommand = Command.make("summary", { | 207 | 212 |
| 208 | 213 | yield* Console.log( | 209 | 214 | summary.spanCount === 0 | 210 | | - ? `No spans found in ${traceFilePath} or its rotated files${window === undefined ? "" : " in that window"}.${summary.skippedLineCount > 0 ? ` Skipped ${summary.skippedLineCount} lines that are not spans.` : ""}` | | 215 | + ? `No spans found in ${traceFilePath} or its rotated files${window === undefined ? "" : " in that window"}.${summary.skippedLineCount > 0 ? ` ${formatSkippedLines(summary.skippedLineCount)}` : ""}` | 211 | 216 | : formatTraceSummary(summary, flags.limit), | 212 | 217 | ); | 213 | 218 | }), | |
|