Skip to content

Commit 5d50b18

Browse files
t3dotggclaude
andcommitted
fix(cli): skip spans with out-of-range end times in t3 trace summary
A span whose end time is past the largest Date made the report throw while formatting timestamps, so one bad record hid the whole summary. Count such lines as skipped instead. The empty-result message now also says how many lines were skipped, and the file read error uses Effect.catchTags to match the repo convention. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 770a360 commit 5d50b18

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ it("drops spans that ended before the window and counts unreadable lines", () =>
7373
span("old", 1, 0),
7474
"{not json",
7575
JSON.stringify({ name: "no-duration" }),
76+
// Ends past the largest Date, so the report could not print it.
77+
JSON.stringify({ name: "far-future", durationMs: 1, endTimeUnixNano: "9".repeat(22) }),
7678
span("recent", 4, 5 * MINUTE_MS),
7779
].forEach(summarizer.addLine);
7880
const summary = summarizer.finish();
7981

80-
assert.strictEqual(summary.skippedLineCount, 2);
82+
assert.strictEqual(summary.skippedLineCount, 3);
8183
assert.deepStrictEqual(
8284
summary.spans.map((entry) => [entry.name, entry.count, entry.perMinute]),
8385
[["recent", 1, undefined]],

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export function makeTraceSpanSummary(sinceMs = -Infinity) {
6666
return;
6767
}
6868
const endMs = span.endTimeUnixNano / 1_000_000;
69+
// The report prints end times as dates, so skip ones outside the Date range.
70+
if (Option.isNone(DateTime.make(endMs))) {
71+
skippedLineCount += 1;
72+
return;
73+
}
6974
if (endMs < sinceMs) return;
7075

7176
spanCount += 1;
@@ -191,25 +196,26 @@ const traceSummaryCommand = Command.make("summary", {
191196
Stream.decodeText,
192197
Stream.splitLines,
193198
Stream.runForEachArray((lines) => Effect.sync(() => lines.forEach(summarizer.addLine))),
194-
Effect.catchTag("PlatformError", (cause) =>
195-
cause.reason._tag === "NotFound"
196-
? Effect.void
197-
: Effect.fail(
198-
new TraceFileReadError({
199-
traceFilePath: path,
200-
causeTag: cause.reason._tag,
201-
cause,
202-
}),
203-
),
204-
),
199+
Effect.catchTags({
200+
PlatformError: (cause) =>
201+
cause.reason._tag === "NotFound"
202+
? Effect.void
203+
: Effect.fail(
204+
new TraceFileReadError({
205+
traceFilePath: path,
206+
causeTag: cause.reason._tag,
207+
cause,
208+
}),
209+
),
210+
}),
205211
),
206212
{ discard: true },
207213
);
208214
const summary = summarizer.finish();
209215

210216
yield* Console.log(
211217
summary.spanCount === 0
212-
? `No spans found in ${traceFilePath} or its rotated files${sinceMs === undefined ? "" : " in that window"}.`
218+
? `No spans found in ${traceFilePath} or its rotated files${sinceMs === undefined ? "" : " in that window"}.${summary.skippedLineCount > 0 ? ` Skipped ${summary.skippedLineCount} lines that are not spans.` : ""}`
213219
: formatTraceSummary(summary, flags.limit),
214220
);
215221
}),

0 commit comments

Comments
 (0)