Skip to content

feat: highlight selected span from results table by default in trace side panel #827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/app/src/components/DBRowDataPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
import { Box } from '@mantine/core';

import { useQueriedChartConfig } from '@/hooks/useChartConfig';
import { getEventBody, getFirstTimestampValueExpression } from '@/source';
import { getDisplayedTimestampValueExpression, getEventBody } from '@/source';

import { DBRowJsonViewer } from './DBRowJsonViewer';

Expand All @@ -17,6 +17,7 @@ export function useRowData({
const eventBodyExpr = getEventBody(source);

const searchedTraceIdExpr = source.traceIdExpression;
const searchedSpanIdExpr = source.spanIdExpression;

const severityTextExpr =
source.severityTextExpression || source.statusCodeExpression;
Expand All @@ -29,9 +30,7 @@ export function useRowData({
valueExpression: '*',
},
{
valueExpression: getFirstTimestampValueExpression(
source.timestampValueExpression,
),
valueExpression: getDisplayedTimestampValueExpression(source),
alias: '__hdx_timestamp',
},
...(eventBodyExpr
Expand All @@ -50,6 +49,14 @@ export function useRowData({
},
]
: []),
...(searchedSpanIdExpr
? [
{
valueExpression: searchedSpanIdExpr,
alias: '__hdx_span_id',
},
]
: []),
...(severityTextExpr
? [
{
Expand Down
18 changes: 17 additions & 1 deletion packages/app/src/components/DBRowSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export default function DBRowSidePanel({
return false;
}, [source.eventAttributesExpression, source.resourceAttributesExpression]);

const defaultTab = hasOverviewPanel ? Tab.Overview : Tab.Parsed;
const defaultTab =
source.kind === 'trace'
? Tab.Trace
: hasOverviewPanel
? Tab.Overview
: Tab.Parsed;

const [queryTab, setQueryTab] = useQueryState(
'tab',
Expand Down Expand Up @@ -239,6 +244,16 @@ export default function DBRowSidePanel({
}
}, [source, normalizedRow]);

const initialRowHighlightHint = useMemo(() => {
if (normalizedRow) {
return {
timestamp: normalizedRow['__hdx_timestamp'],
spanId: normalizedRow['__hdx_span_id'],
body: normalizedRow['__hdx_body'],
};
}
}, [normalizedRow]);

return (
<Drawer
customIdSuffix={`log-side-panel-${rowId}`}
Expand Down Expand Up @@ -357,6 +372,7 @@ export default function DBRowSidePanel({
traceId={traceId}
dateRange={oneHourRange}
focusDate={focusDate}
initialRowHighlightHint={initialRowHighlightHint}
/>
</Box>
</ErrorBoundary>
Expand Down
10 changes: 10 additions & 0 deletions packages/app/src/components/DBTracePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ export default function DBTracePanel({
dateRange,
focusDate,
parentSourceId,
initialRowHighlightHint,
}: {
parentSourceId?: string | null;
childSourceId?: string | null;
traceId: string;
dateRange: [Date, Date];
focusDate: Date;
// Passed in from side panel to try to identify which
// span in the chart to highlight first without constructing
// a full row where clause
initialRowHighlightHint?: {
timestamp: string;
spanId: string;
body: string;
};
}) {
const { control, watch, setValue } = useForm({
defaultValues: {
Expand Down Expand Up @@ -191,6 +200,7 @@ export default function DBTracePanel({
focusDate={focusDate}
highlightedRowWhere={eventRowWhere?.id}
onClick={setEventRowWhere}
initialRowHighlightHint={initialRowHighlightHint}
/>
)}
{traceSourceData != null && eventRowWhere != null && (
Expand Down
27 changes: 26 additions & 1 deletion packages/app/src/components/DBTraceWaterfallChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import _ from 'lodash';
import TimestampNano from 'timestamp-nano';
import {
Expand Down Expand Up @@ -244,6 +244,7 @@ export function DBTraceWaterfallChartContainer({
focusDate,
onClick,
highlightedRowWhere,
initialRowHighlightHint,
}: {
traceTableSource: TSource;
logTableSource: TSource | null;
Expand All @@ -252,6 +253,11 @@ export function DBTraceWaterfallChartContainer({
focusDate: Date;
onClick?: (rowWhere: { id: string; type: string }) => void;
highlightedRowWhere?: string | null;
initialRowHighlightHint?: {
timestamp: string;
spanId: string;
body: string;
};
}) {
const { rows: traceRowsData, isFetching: traceIsFetching } =
useEventsAroundFocus({
Expand Down Expand Up @@ -287,6 +293,25 @@ export function DBTraceWaterfallChartContainer({
}
});

useEffect(() => {
if (initialRowHighlightHint && onClick && highlightedRowWhere == null) {
const initialRowHighlightIndex = rows.findIndex(row => {
return (
row.Timestamp === initialRowHighlightHint.timestamp &&
row.SpanId === initialRowHighlightHint.spanId &&
row.Body === initialRowHighlightHint.body
);
});

if (initialRowHighlightIndex !== -1) {
onClick?.({
id: rows[initialRowHighlightIndex].id,
type: rows[initialRowHighlightIndex].type ?? '',
});
}
}
}, [initialRowHighlightHint, rows, onClick, highlightedRowWhere]);

// 3 Edge-cases
// 1. No spans, just logs (ex. sampling)
// 2. Spans, but with missing spans inbetween (ex. missing intermediary spans)
Expand Down