Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: expand waterfall ancestors on flamegraph click (#11373)

Aditya Singhe634eb4452fd
diff --git a/frontend/src/pages/TraceDetailsV3/SpanDetailsPanel/SpanDetailsPanel.tsx b/frontend/src/pages/TraceDetailsV3/SpanDetailsPanel/SpanDetailsPanel.tsx
index dd8e03f9d7..03dc80a006 100644
--- a/frontend/src/pages/TraceDetailsV3/SpanDetailsPanel/SpanDetailsPanel.tsx
+++ b/frontend/src/pages/TraceDetailsV3/SpanDetailsPanel/SpanDetailsPanel.tsx
@@ -526,7 +526,7 @@ function SpanDetailsPanel({
const PANEL_WIDTH = 500;
const PANEL_MARGIN_RIGHT = 20;
- const PANEL_MARGIN_TOP = 25;
+ const PANEL_MARGIN_TOP = 50;
const PANEL_MARGIN_BOTTOM = 25;
const content = (
diff --git a/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx b/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx
index 5085be5d17..7e5e3afdd7 100644
--- a/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx
+++ b/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/Success.tsx
@@ -580,10 +580,9 @@ function Success(props: ISuccessProps): JSX.Element {
}
return next;
});
+ return;
}
- // Backend mode: trigger API call (current behavior)
- // keeping this for both mode to support scroll to view to function well.
- // interestedspan would not make api call in frontend mode so it is safe to use for both mode.
+ // Backend mode: trigger refetch via interestedSpanId
setInterestedSpanId({
spanId,
isUncollapsed: !collapse,
@@ -782,19 +781,26 @@ function Success(props: ISuccessProps): JSX.Element {
[],
);
+ // Backend mode: scroll + select to the interestedSpanId target. `spans` in
+ // deps so we retry once a refetch lands (chevron / pagination / deep-link).
useEffect(() => {
- if (interestedSpanId.spanId !== '') {
- const idx = spans.findIndex(
- (span) => span.span_id === interestedSpanId.spanId,
- );
- if (idx !== -1) {
- scrollSpanIntoView(spans[idx], spans);
- setSelectedSpan(spans[idx]);
- }
- } else {
- setSelectedSpan((prev) => prev ?? spans[0]);
+ if (isFullDataLoaded || interestedSpanId.spanId === '') {
+ return;
+ }
+ const idx = spans.findIndex(
+ (span) => span.span_id === interestedSpanId.spanId,
+ );
+ if (idx !== -1) {
+ scrollSpanIntoView(spans[idx], spans);
+ setSelectedSpan(spans[idx]);
}
- }, [interestedSpanId, setSelectedSpan, spans, scrollSpanIntoView]);
+ }, [
+ interestedSpanId,
+ setSelectedSpan,
+ spans,
+ scrollSpanIntoView,
+ isFullDataLoaded,
+ ]);
// Covers URL-driven navigation to an already-loaded span (flamegraph /
// filter / browser back) that the interestedSpanId-keyed effect doesn't see.
diff --git a/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/__tests__/UnifiedSpanClick.test.tsx b/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/__tests__/UnifiedSpanClick.test.tsx
index c42a6f4d1f..2981736c1a 100644
--- a/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/__tests__/UnifiedSpanClick.test.tsx
+++ b/frontend/src/pages/TraceDetailsV3/TraceWaterfall/TraceWaterfallStates/Success/__tests__/UnifiedSpanClick.test.tsx
@@ -199,10 +199,12 @@ const mockSpans = [
createMockSpan('span-3', 1),
];
-// Shared TestComponent for all tests
+// Shared TestComponent for all tests. Default selectedSpan to the root mirrors
+// what TraceDetailsV3's deep-link one-shot effect does when there's no spanId
+// in the URL — Success no longer owns that default itself.
function TestComponent(): JSX.Element {
const [selectedSpan, setSelectedSpan] = React.useState<SpanV3 | undefined>(
- undefined,
+ mockSpans[0],
);
return (
diff --git a/frontend/src/pages/TraceDetailsV3/index.tsx b/frontend/src/pages/TraceDetailsV3/index.tsx
index 4fb08a1a47..0e6f45b188 100644
--- a/frontend/src/pages/TraceDetailsV3/index.tsx
+++ b/frontend/src/pages/TraceDetailsV3/index.tsx
@@ -75,6 +75,7 @@ function TraceDetailsV3(): JSX.Element {
});
const allSpansRef = useRef<SpanV3[]>([]);
+ const deepLinkResolvedRef = useRef(false);
// Refetch only when the URL target isn't already loaded. Keeps row clicks
// and other in-window URL navigation from triggering a backend window slide.
@@ -175,12 +176,36 @@ function TraceDetailsV3(): JSX.Element {
}
}, [traceData, isFullDataLoaded]);
- // Frontend mode: auto-expand ancestors of the selected span so it becomes visible
+ // Tracks whether we've already done the initial URL→selectedSpan handoff
+ //Lets `interestedSpanId` stay purely as the refetch trigger in frontend mode.
useEffect(() => {
- if (!isFullDataLoaded || !interestedSpanId.spanId || allSpans.length === 0) {
+ if (deepLinkResolvedRef.current) {
return;
}
- const ancestors = getAncestorSpanIds(allSpans, interestedSpanId.spanId);
+ if (allSpans.length === 0) {
+ return;
+ }
+ if (selectedSpanId) {
+ const span = allSpans.find((s) => s.span_id === selectedSpanId);
+ if (!span) {
+ // Span not in the current window — wait for more data (backend
+ // pagination) before marking resolved.
+ return;
+ }
+ setSelectedSpan(span);
+ } else {
+ setSelectedSpan((prev) => prev ?? allSpans[0]);
+ }
+ deepLinkResolvedRef.current = true;
+ }, [selectedSpanId, allSpans]);
+
+ // Frontend mode: auto-expand ancestors of the URL-targeted span so it's
+ // visible. Keyed on URL `spanId`(selectedSpanId).
+ useEffect(() => {
+ if (!isFullDataLoaded || !selectedSpanId || allSpans.length === 0) {
+ return;
+ }
+ const ancestors = getAncestorSpanIds(allSpans, selectedSpanId);
if (ancestors.size === 0) {
return;
}
@@ -203,7 +228,7 @@ function TraceDetailsV3(): JSX.Element {
}
return next;
});
- }, [isFullDataLoaded, interestedSpanId.spanId, allSpans]);
+ }, [isFullDataLoaded, selectedSpanId, allSpans]);
const [activeKeys, setActiveKeys] = useState<string[]>(['flame', 'waterfall']);
@@ -217,7 +242,7 @@ function TraceDetailsV3(): JSX.Element {
() =>
(getLocalStorageKey(
LOCALSTORAGE.TRACE_DETAILS_SPAN_DETAILS_POSITION,
- ) as SpanDetailVariant) || SpanDetailVariant.DOCKED,
+ ) as SpanDetailVariant) || SpanDetailVariant.DIALOG,
);
const handleVariantChange = useCallback(