Skip to content

Commit 0986eaf

Browse files
committed
fix waterfall timing display sync issue
Use span.endTime === null instead of span.status === 'running' to determine if a span is still in progress. This ensures the bar style (arrow vs dot) and duration display are always in sync, since endTime is the actual source of truth for timing data.
1 parent 5032f80 commit 0986eaf

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/spanTree.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ function getTimeRange(node: TreeNode): {
242242
const minTime = rootSpan.startTime;
243243
let maxTime = rootSpan.endTime ?? rootSpan.startTime;
244244

245-
// If root is still running, extend the range
246-
if (rootSpan.status === "running") {
245+
// If root is still running (no endTime), extend the range
246+
if (rootSpan.endTime === null) {
247247
const extension = (maxTime - minTime) / 2n;
248248
maxTime = maxTime + (extension > 0n ? extension : 1000000000n); // At least 1 second
249249
}
@@ -260,7 +260,8 @@ function getWaterfallOffsets(
260260
node: TreeNode,
261261
): { startOffset: number; endOffset: number } {
262262
const range = getTimeRange(node);
263-
const isRunning = span.status === "running";
263+
// Use endTime to determine if span is still running (more reliable than status)
264+
const isRunning = span.endTime === null;
264265

265266
let startOffset = 0;
266267
let endOffset = 1;
@@ -390,14 +391,14 @@ export function SpanTreeView(props: {
390391
const statusColor = () =>
391392
span.status === "running" ? theme.warning : theme.success;
392393

393-
const duration = formatDuration(span);
394-
395394
// Build the row content - consistent column layout
396395
// 2 columns always: [tree+name] [duration]
397396
// 3 columns with waterfall: [tree+name] [waterfall bar] [duration]
398397
const rowContent = () => {
399398
const selector = isSelected() ? "> " : " ";
400399
const prefix = getTreePrefix(node, props.expandedSpanIds);
400+
// Duration must be computed inside reactive function to update when span changes
401+
const duration = formatDuration(span);
401402

402403
const TREE_NAME_WIDTH = 24; // Fixed width for tree prefix + span name combined
403404
const DURATION_WIDTH = 10; // Fixed width for duration
@@ -411,6 +412,8 @@ export function SpanTreeView(props: {
411412

412413
if (props.showWaterfall && props.waterfallBarWidth) {
413414
// With waterfall bar
415+
// Use endTime to determine if span is still running (more reliable than status)
416+
const isRunning = span.endTime === null;
414417
const { startOffset, endOffset } = getWaterfallOffsets(
415418
span,
416419
node,
@@ -419,7 +422,7 @@ export function SpanTreeView(props: {
419422
startOffset,
420423
endOffset,
421424
props.waterfallBarWidth,
422-
span.status === "running",
425+
isRunning,
423426
node.depth === 0,
424427
);
425428

0 commit comments

Comments
 (0)