Skip to content

Commit dc37768

Browse files
committed
feat: browser event summary in row side panel
1 parent 0bb96d4 commit dc37768

14 files changed

Lines changed: 722 additions & 10 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
feat: Row side panel summarizes clicks, navigations and console messages from OpenTelemetry browser SDKs, and navigation rows no longer show an HTTP Request section
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {
2+
BrowserEventKind,
3+
CONSOLE_METHOD_ATTRIBUTE,
4+
firstLine,
5+
getElementAttributes,
6+
} from '@/utils/browserEvents';
7+
import {
8+
Attributes,
9+
firstSetString,
10+
isSet,
11+
} from '@/utils/spanAttributeReaders';
12+
13+
import { RequestDetailRow, RequestDetailsTable } from './RequestDetailsTable';
14+
15+
const PAGE_URL_KEY = 'browser.document.url.full';
16+
17+
function read(attributes: Attributes, key: string): string | undefined {
18+
return firstSetString(attributes, [key]);
19+
}
20+
21+
// Map columns hold the flag as 'true'/'false', JSON columns as a Bool.
22+
function yesNo(value: unknown): string | undefined {
23+
if (!isSet(value)) {
24+
return undefined;
25+
}
26+
return String(value) === 'true' ? 'Yes' : 'No';
27+
}
28+
29+
function getClickRows(attributes: Attributes): RequestDetailRow[] {
30+
return [
31+
['Element', read(attributes, 'browser.tag_name')?.toLowerCase()],
32+
['CSS selector', read(attributes, 'browser.css_selector')],
33+
...getElementAttributes(attributes).map(
34+
([name, value]): RequestDetailRow => [`data-otel-${name}`, value],
35+
),
36+
['Page URL', read(attributes, PAGE_URL_KEY)],
37+
];
38+
}
39+
40+
function getNavigationRows(attributes: Attributes): RequestDetailRow[] {
41+
return [
42+
['URL', read(attributes, 'url.full')],
43+
['Navigation type', read(attributes, 'browser.navigation.type')],
44+
['Same document', yesNo(attributes['browser.navigation.same_document'])],
45+
['Hash change', yesNo(attributes['browser.navigation.hash_change'])],
46+
];
47+
}
48+
49+
function getConsoleRows(
50+
attributes: Attributes,
51+
body: string | undefined,
52+
): RequestDetailRow[] {
53+
return [
54+
['Method', read(attributes, CONSOLE_METHOD_ATTRIBUTE)],
55+
// The SDK sends the console message as the body, never as an attribute.
56+
['Message', body ? firstLine(body) : undefined],
57+
['Page URL', read(attributes, PAGE_URL_KEY)],
58+
];
59+
}
60+
61+
export function BrowserEventSubpanel({
62+
kind,
63+
attributes,
64+
body,
65+
}: {
66+
kind: BrowserEventKind;
67+
/** The row's flattened event attributes. */
68+
attributes: Attributes;
69+
body: string | undefined;
70+
}) {
71+
const rows =
72+
kind === 'click'
73+
? getClickRows(attributes)
74+
: kind === 'navigation'
75+
? getNavigationRows(attributes)
76+
: getConsoleRows(attributes, body);
77+
return <RequestDetailsTable rows={rows} />;
78+
}

‎packages/app/src/components/DBRowDataPanel.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export enum ROW_DATA_ALIASES {
4343
DURATION_MS = '__hdx_duration_ms',
4444
SPAN_KIND = '__hdx_span_kind',
4545
SPAN_LINKS = '__hdx_span_links',
46+
EVENT_NAME = '__hdx_event_name',
4647
}
4748

4849
export function useRowData({
@@ -97,6 +98,18 @@ export function useRowData({
9798
// select that instead of `*` when fetching full row data.
9899
const knownColumns = getKnownColumnsList(source);
99100

101+
// A bare column comes back from `*` or the Known Columns List whenever the
102+
// table has it, so it is read from the row instead of selected: older OTel
103+
// log tables have no EventName column, and selecting it would fail the whole
104+
// lookup.
105+
const eventNameExpr = isLogSource(source)
106+
? source.eventNameExpression?.trim()
107+
: undefined;
108+
const eventNameColumn =
109+
eventNameExpr && /^[A-Za-z_][A-Za-z0-9_]*$/.test(eventNameExpr)
110+
? eventNameExpr
111+
: undefined;
112+
100113
const baseConfig = {
101114
source: source.id,
102115
connection: source.connection,
@@ -168,6 +181,14 @@ export function useRowData({
168181
},
169182
]
170183
: []),
184+
...(eventNameExpr && eventNameColumn == null
185+
? [
186+
{
187+
valueExpression: eventNameExpr,
188+
alias: ROW_DATA_ALIASES.EVENT_NAME,
189+
},
190+
]
191+
: []),
171192
...(source.kind === SourceKind.Trace && source.spanEventsValueExpression
172193
? [
173194
{
@@ -288,11 +309,15 @@ export function useRowData({
288309
);
289310
}
290311

312+
if (eventNameColumn != null) {
313+
normalizedRow[ROW_DATA_ALIASES.EVENT_NAME] = row[eventNameColumn];
314+
}
315+
291316
return {
292317
...queryResult.data,
293318
data: [normalizedRow],
294319
};
295-
}, [queryResult.data]);
320+
}, [queryResult.data, eventNameColumn]);
296321

297322
return {
298323
...queryResult,

‎packages/app/src/components/DBRowOverviewPanel.tsx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { use, useCallback, useMemo } from 'react';
22
import isString from 'lodash/isString';
33
import pickBy from 'lodash/pickBy';
4-
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
4+
import {
5+
isLogSource,
6+
SourceKind,
7+
TSource,
8+
} from '@hyperdx/common-utils/dist/types';
59
import { Accordion, Box, Flex, Text } from '@mantine/core';
610

711
import { WithClause } from '@/hooks/useRowWhere';
812
import { getEventBody } from '@/source';
13+
import { getBrowserEventKind, isBrowserEventRow } from '@/utils/browserEvents';
914
import { getHighlightedAttributesFromData } from '@/utils/highlightedAttributes';
1015
import { resolveRowTimestampAnchor } from '@/utils/rowTimestamps';
1116
import { getRequestPanelTitle } from '@/utils/rpcSpanAttributes';
1217
import { isSet } from '@/utils/spanAttributeReaders';
1318

19+
import { BrowserEventSubpanel } from './BrowserEventSubpanel';
1420
import {
1521
getJSONColumnNames,
1622
getMapColumnNames,
@@ -147,6 +153,24 @@ export function RowOverviewPanel({
147153
[flattenedEventAttributes],
148154
);
149155

156+
// Only log sources select the event name, and gating here keeps every trace
157+
// row out whatever attributes it carries.
158+
const { browserEventKind, isBrowserRow } = useMemo(() => {
159+
if (!isLogSource(source)) {
160+
return { browserEventKind: undefined, isBrowserRow: false };
161+
}
162+
163+
const row = {
164+
eventName: firstRow?.__hdx_event_name,
165+
attributes: flattenedEventAttributes,
166+
};
167+
168+
return {
169+
browserEventKind: getBrowserEventKind(row),
170+
isBrowserRow: isBrowserEventRow(row),
171+
};
172+
}, [source, firstRow?.__hdx_event_name, flattenedEventAttributes]);
173+
150174
const exceptionAttributes = useMemo(() => {
151175
const spanEventAttributes = firstRow?.__hdx_events_exception_attributes;
152176
if (
@@ -249,6 +273,7 @@ export function RowOverviewPanel({
249273
// In that case suppress the body paper entirely instead of
250274
// rendering an "[Empty]" placeholder.
251275
bodyConfigured={mainContentColumn !== undefined}
276+
hideEmptyBody={isBrowserRow}
252277
severityText={firstRow?.__hdx_severity_text}
253278
rowData={firstRow}
254279
/>
@@ -258,6 +283,7 @@ export function RowOverviewPanel({
258283
mt="sm"
259284
defaultValue={[
260285
'exception',
286+
'browserEvent',
261287
'spanEvents',
262288
'spanLinks',
263289
'linkedFrom',
@@ -289,7 +315,29 @@ export function RowOverviewPanel({
289315
</Accordion.Item>
290316
)}
291317

292-
{requestPanelTitle != null && (
318+
{browserEventKind != null && (
319+
<Accordion.Item
320+
value="browserEvent"
321+
data-testid="browser-event-section"
322+
>
323+
<Accordion.Control>
324+
<Text size="sm" ps={contentPx}>
325+
Browser event
326+
</Text>
327+
</Accordion.Control>
328+
<Accordion.Panel>
329+
<Box px={contentPx}>
330+
<BrowserEventSubpanel
331+
kind={browserEventKind}
332+
attributes={flattenedEventAttributes}
333+
body={mainContent}
334+
/>
335+
</Box>
336+
</Accordion.Panel>
337+
</Accordion.Item>
338+
)}
339+
340+
{requestPanelTitle != null && browserEventKind == null && (
293341
<Accordion.Item value="network">
294342
<Accordion.Control>
295343
<Text size="sm" ps={contentPx}>

‎packages/app/src/components/DBRowSidePanel.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import TabBar from '@/TabBar';
5252
import { SearchConfig } from '@/types';
5353
import { FormatTime } from '@/useFormatTime';
5454
import { formatDistanceToNowStrictShort } from '@/utils';
55+
import { isBrowserEventRow } from '@/utils/browserEvents';
5556
import { getHighlightedAttributesFromData } from '@/utils/highlightedAttributes';
5657
import {
5758
getRowLookupWindow,
@@ -1075,6 +1076,13 @@ export const DBRowSidePanelInner = ({
10751076
attributes={highlightedAttributeValues}
10761077
mainContent={mainContent}
10771078
mainContentHeader={mainContentColumn}
1079+
hideEmptyBody={
1080+
isLogSource(source) &&
1081+
isBrowserEventRow({
1082+
eventName: normalizedRow?.[ROW_DATA_ALIASES.EVENT_NAME],
1083+
attributes: normalizedRow?.[ROW_DATA_ALIASES.EVENT_ATTRIBUTES],
1084+
})
1085+
}
10781086
severityText={severityText}
10791087
rowData={normalizedRow}
10801088
/>

‎packages/app/src/components/DBRowSidePanelHeader.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ export default function DBRowSidePanelHeader({
2424
// source has neither body nor implicit column configured), the body
2525
// paper is suppressed entirely; the highlighted attributes still render.
2626
bodyConfigured = true,
27+
// Rows that never carry a body, such as browser events, skip the empty state.
28+
hideEmptyBody = false,
2729
severityText,
2830
rowData,
2931
}: {
3032
mainContent?: string;
3133
mainContentHeader?: string;
3234
bodyConfigured?: boolean;
35+
hideEmptyBody?: boolean;
3336
attributes?: HighlightedAttribute[];
3437
severityText?: string;
3538
rowData?: Record<string, any>;
@@ -85,7 +88,8 @@ export default function DBRowSidePanelHeader({
8588

8689
return (
8790
<>
88-
{!bodyConfigured ? null : mainContent ? (
91+
{!bodyConfigured ||
92+
(hideEmptyBody && !mainContent) ? null : mainContent ? (
8993
<Paper
9094
p="xs"
9195
mt="sm"

‎packages/app/src/components/__tests__/DBRowDataPanel.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,61 @@ describe('DBRowDataPanel', () => {
126126
expect(config.select).not.toContainEqual({ valueExpression: '*' });
127127
});
128128

129+
describe('event name', () => {
130+
const eventNameAlias = expect.objectContaining({
131+
alias: '__hdx_event_name',
132+
});
133+
const lookUp = (
134+
overrides: Partial<TLogSource>,
135+
row: Record<string, unknown> = {},
136+
) => {
137+
mockUseQueriedChartConfig.mockReturnValue({
138+
data: { data: [row], meta: [], rows: 1, isComplete: true },
139+
isLoading: false,
140+
isError: false,
141+
isSuccess: true,
142+
});
143+
const { result } = renderHook(() =>
144+
useRowData({ source: { ...source, ...overrides }, rowId: "id='a'" }),
145+
);
146+
return {
147+
select: mockUseQueriedChartConfig.mock.calls[0][0].select,
148+
row: result.current.data?.data[0],
149+
};
150+
};
151+
152+
it('reads a bare column from the row instead of selecting it', () => {
153+
const { select, row } = lookUp(
154+
{ eventNameExpression: 'EventName' },
155+
{ EventName: 'browser.navigation' },
156+
);
157+
expect(select).not.toContainEqual(eventNameAlias);
158+
expect(row?.__hdx_event_name).toBe('browser.navigation');
159+
});
160+
161+
it('leaves the event name unset when the table has no such column', () => {
162+
const { select, row } = lookUp({ eventNameExpression: 'EventName' });
163+
expect(select).not.toContainEqual(eventNameAlias);
164+
expect(row?.__hdx_event_name).toBeUndefined();
165+
});
166+
167+
it('selects any other expression under the alias', () => {
168+
const { select } = lookUp({
169+
eventNameExpression: "LogAttributes['event.name']",
170+
});
171+
expect(select).toContainEqual({
172+
valueExpression: "LogAttributes['event.name']",
173+
alias: '__hdx_event_name',
174+
});
175+
});
176+
177+
it('reads no event name when the expression is unset', () => {
178+
const { select, row } = lookUp({}, { EventName: 'browser.navigation' });
179+
expect(select).not.toContainEqual(eventNameAlias);
180+
expect(row?.__hdx_event_name).toBeUndefined();
181+
});
182+
});
183+
129184
it('adds no query settings while the viewer option is off', () => {
130185
renderHook(() => useRowData({ source, rowId: "id='abc123'" }));
131186

0 commit comments

Comments
 (0)