GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(cli): use singular counts in one-span trace summaries (#43231) · patroza/t3code@e380d41

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/cli
    • trace.test.ts
    • trace.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/cli/trace.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/cli/trace.test.ts
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,26 @@ it("formats large summaries without overflowing the call stack", () => {
140140
"long-span-name 1 1.0 1ms 1ms 1ms 0 0",
141141
);
142142
});
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

‎apps/server/src/cli/trace.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/cli/trace.ts
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ export function makeTraceSpanSummary(window?: { nowMs: number; duration: Duratio
122122
return { addLine, finish };
123123
}
124124

125+
const formatSkippedLines = (count: number) =>
126+
count === 1 ? "Skipped 1 line that is not a span." : `Skipped ${count} lines that are not spans.`;
127+
125128
const formatMs = (ms: number) =>
126129
Math.round(ms) < 1_000 ? `${Math.round(ms)}ms` : `${Math.round(ms / 100) / 10}s`;
127130

@@ -151,11 +154,10 @@ export function formatTraceSummary(
151154
table.reduce((max, row) => Math.max(max, row[column]!.length), 0),
152155
);
153156
const formatIso = (ms: number) => DateTime.formatIso(DateTime.makeUnsafe(ms));
157+
const hiddenCount = summary.spans.length - limit;
154158
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)] : []),
159161
"",
160162
...table.map((row) =>
161163
row
@@ -164,8 +166,11 @@ export function formatTraceSummary(
164166
)
165167
.join(" "),
166168
),
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+
]
169174
: []),
170175
].join("\n");
171176
}
@@ -207,7 +212,7 @@ const traceSummaryCommand = Command.make("summary", {
207212

208213
yield* Console.log(
209214
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)}` : ""}`
211216
: formatTraceSummary(summary, flags.limit),
212217
);
213218
}),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.