Skip to content

Commit f7198cc

Browse files
committed
fix: address review feedback from Cursor BugBot
- Remove dead code: flattenSpanTree (unused, superseded by EAP API) - Remove dead code: writeSpanTable (superseded by formatSpanTable) - Fix case-insensitive span ID matching in findSpanById — lowercase the API-returned span_id before comparing with user-lowercased input - Fix JSON duration consistency: use computeSpanDurationMs() in buildJsonResults instead of raw r.span.duration, matching the human output path's timestamp-arithmetic fallback
1 parent e6727e1 commit f7198cc

File tree

2 files changed

+4
-50
lines changed

2 files changed

+4
-50
lines changed

src/commands/span/view.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from "../../lib/formatters/index.js";
2222
import { filterFields } from "../../lib/formatters/json.js";
2323
import { CommandOutput } from "../../lib/formatters/output.js";
24+
import { computeSpanDurationMs } from "../../lib/formatters/trace.js";
2425
import {
2526
applyFreshFlag,
2627
FRESH_ALIASES,
@@ -217,7 +218,7 @@ function buildJsonResults(results: SpanResult[], traceId: string): unknown[] {
217218
description: r.span.description || r.span.transaction,
218219
start_timestamp: r.span.start_timestamp,
219220
end_timestamp: r.span.end_timestamp || r.span.timestamp,
220-
duration: r.span.duration,
221+
duration: computeSpanDurationMs(r.span),
221222
project_slug: r.span.project_slug,
222223
transaction: r.span.transaction,
223224
depth: r.depth,

src/lib/formatters/trace.ts

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
renderMarkdown,
2424
stripColorTags,
2525
} from "./markdown.js";
26-
import { type Column, formatTable, writeTable } from "./table.js";
26+
import { type Column, formatTable } from "./table.js";
2727
import { renderTextTable } from "./text-table.js";
2828

2929
/**
@@ -324,40 +324,6 @@ export type FlatSpan = {
324324
child_count?: number;
325325
};
326326

327-
/**
328-
* Flatten a hierarchical TraceSpan[] tree into a depth-first flat array.
329-
*
330-
* @param spans - Root-level spans from the /trace/ API
331-
* @returns Flat array with depth and child_count computed
332-
*/
333-
export function flattenSpanTree(spans: TraceSpan[]): FlatSpan[] {
334-
const result: FlatSpan[] = [];
335-
336-
function walk(span: TraceSpan, depth: number): void {
337-
const children = span.children ?? [];
338-
result.push({
339-
span_id: span.span_id,
340-
parent_span_id: span.parent_span_id,
341-
op: span.op || span["transaction.op"],
342-
description: span.description || span.transaction,
343-
duration_ms: computeSpanDurationMs(span),
344-
start_timestamp: span.start_timestamp,
345-
project_slug: span.project_slug,
346-
transaction: span.transaction,
347-
depth,
348-
child_count: children.length,
349-
});
350-
for (const child of children) {
351-
walk(child, depth + 1);
352-
}
353-
}
354-
355-
for (const span of spans) {
356-
walk(span, 0);
357-
}
358-
return result;
359-
}
360-
361327
/** Result of finding a span by ID in the tree */
362328
export type FoundSpan = {
363329
span: TraceSpan;
@@ -381,7 +347,7 @@ export function findSpanById(
381347
depth: number,
382348
ancestors: TraceSpan[]
383349
): FoundSpan | null {
384-
if (span.span_id === spanId) {
350+
if (span.span_id.toLowerCase() === spanId) {
385351
return { span, depth, ancestors };
386352
}
387353
for (const child of span.children ?? []) {
@@ -490,19 +456,6 @@ export function formatSpanTable(spans: FlatSpan[]): string {
490456
return formatTable(spans, SPAN_TABLE_COLUMNS, { truncate: true });
491457
}
492458

493-
/**
494-
* Write a flat span list as a formatted table.
495-
*
496-
* @param stdout - Output writer
497-
* @param spans - Flat span array to display
498-
*/
499-
export function writeSpanTable(
500-
stdout: { write(s: string): void },
501-
spans: FlatSpan[]
502-
): void {
503-
writeTable(stdout, spans, SPAN_TABLE_COLUMNS, { truncate: true });
504-
}
505-
506459
/**
507460
* Build key-value rows for a span's metadata.
508461
*/

0 commit comments

Comments
 (0)