Skip to content

Commit 4d22bca

Browse files
Copilotyurishkuro
andcommitted
Ensure childSpans is always initialized to prevent undefined access
Initialize childSpans to empty array for all spans when they're created in transform-trace-data, before the tree walk. This ensures childSpans is always defined as per the Span type definition (childSpans: Array<Span>). Previously, childSpans was only populated during tree walk, which could leave it undefined for spans not in the tree or in edge cases. This violated the type contract and required defensive null checks in consuming code. Also removed unnecessary null check in sanitizeOverFlowingChildren since childSpans is now guaranteed to be defined. This fixes the issue where childSpans could be undefined despite being typed as a required array. Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
1 parent fa834f7 commit 4d22bca

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

packages/jaeger-ui/src/components/TracePage/CriticalPath/utils/sanitizeOverFlowingChildren.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const sanitizeOverFlowingChildren = (spanMap: Map<string, Span>): Map<string, Sp
8989
// Second pass: filter out dropped children from childSpans arrays
9090
const finalSpanMap = new Map<string, Span>();
9191
newSpanMap.forEach((span, spanId) => {
92-
const filteredChildSpans = (span.childSpans || []).filter(child => !droppedSpanIds.has(child.spanID));
92+
const filteredChildSpans = span.childSpans.filter(child => !droppedSpanIds.has(child.spanID));
9393

9494
// Update child span references with sanitized parent
9595
let updatedReferences = span.references;

packages/jaeger-ui/src/model/transform-trace-data.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[]
101101
spanIdCounts.set(spanID, 1);
102102
}
103103
span.process = data.processes[processID];
104+
span.childSpans = []; // Initialize to empty array, will be populated during tree walk
104105
spanMap.set(spanID, span);
105106
}
106107
// tree is necessary to sort the spans, so children follow parents, and

0 commit comments

Comments
 (0)