Skip to content

Commit 0bb96d4

Browse files
committed
feat: browser events in session replay
1 parent ac7f76e commit 0bb96d4

19 files changed

Lines changed: 1417 additions & 23 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: Session replay shows clicks, navigations, console output and exceptions from OpenTelemetry browser SDKs

‎packages/app/src/Playbar.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { keepPreviousData } from '@tanstack/react-query';
55

66
import { useQueriedChartConfig } from '@/hooks/useChartConfig';
77

8+
import { mergeLogMarkers, SessionLogEvent } from './utils/sessionLogEvents';
89
import {
910
getSessionRowHttp,
1011
SessionRow,
@@ -21,13 +22,15 @@ export default function Playbar({
2122
playbackRange,
2223
focus,
2324
queriedConfig,
25+
logEvents,
2426
}: {
2527
playerState: 'playing' | 'paused';
2628
setPlayerState: (playerState: 'playing' | 'paused') => void;
2729
focus: { ts: number; setBy: string } | undefined;
2830
setFocus: (focus: { ts: number; setBy: string }) => void;
2931
playbackRange: [Date, Date];
3032
queriedConfig: ChartConfigWithOptDateRange;
33+
logEvents: SessionLogEvent[];
3134
}) {
3235
// might be outdated? state update or something? that's why the max slider val can be wrong?
3336
const minTs = playbackRange[0].getTime();
@@ -49,7 +52,7 @@ export default function Playbar({
4952
[data?.data],
5053
);
5154

52-
const markers = useMemo<PlaybarMarker[]>(() => {
55+
const spanMarkers = useMemo<PlaybarMarker[]>(() => {
5356
return uniqBy(
5457
events
5558
.map(event => {
@@ -111,6 +114,10 @@ export default function Playbar({
111114
'percentage',
112115
);
113116
}, [events, maxTs, minTs]);
117+
const markers = useMemo(
118+
() => mergeLogMarkers(spanMarkers, logEvents, minTs, maxTs),
119+
[spanMarkers, logEvents, minTs, maxTs],
120+
);
114121

115122
return (
116123
<PlaybarSlider

‎packages/app/src/SessionEventList.tsx‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import { useVirtualizer } from '@tanstack/react-virtual';
1616
import useRowWhere, { RowWhereResult } from '@/hooks/useRowWhere';
1717

1818
import { useQueriedChartConfig } from './hooks/useChartConfig';
19+
import { useLogEventRows } from './hooks/useSessionLogEvents';
20+
import type {
21+
SessionEventOpen,
22+
SessionLogEvents,
23+
} from './utils/sessionLogEvents';
1924
import {
2025
getSessionRowHttp,
2126
SessionRow,
@@ -28,7 +33,7 @@ import styles from '@styles/SessionSubpanelV2.module.scss';
2833

2934
type SessionEvent = {
3035
id: string;
31-
row: SessionRow; // original row object
36+
open: SessionEventOpen;
3237
isError: boolean;
3338
isSuccess: boolean;
3439
eventSource: 'navigation' | 'chat' | 'network' | 'custom' | 'log';
@@ -96,6 +101,7 @@ const EventRow = ({
96101
export const SessionEventList = ({
97102
queriedConfig,
98103
aliasMap,
104+
logEvents,
99105
onClick,
100106
onTimeClick,
101107
focus,
@@ -105,6 +111,7 @@ export const SessionEventList = ({
105111
}: {
106112
queriedConfig: ChartConfigWithOptDateRange;
107113
aliasMap: Record<string, string>;
114+
logEvents: SessionLogEvents;
108115
// highlightedResultId: string | undefined;
109116
focus: { ts: number; setBy: string } | undefined;
110117
minTs: number;
@@ -130,7 +137,7 @@ export const SessionEventList = ({
130137

131138
const getRowWhere = useRowWhere({ meta: data?.meta, aliasMap });
132139

133-
const rows = React.useMemo(() => {
140+
const spanRows = React.useMemo(() => {
134141
return (
135142
events.map(event => {
136143
const { timestamp, durationInMs } = event;
@@ -167,7 +174,7 @@ export const SessionEventList = ({
167174

168175
return {
169176
id: event.id,
170-
row: event,
177+
open: { kind: 'span', row: event },
171178
isError,
172179
isSuccess,
173180
eventSource: isNavigation
@@ -216,6 +223,7 @@ export const SessionEventList = ({
216223
}) ?? []
217224
);
218225
}, [events, showRelativeTime, minTs, formatTime]);
226+
const rows = useLogEventRows(spanRows, logEvents, showRelativeTime, minTs);
219227

220228
const parentRef = React.useRef<HTMLDivElement>(null);
221229

@@ -244,7 +252,7 @@ export const SessionEventList = ({
244252
}
245253
}, [currentEventIndex, eventsFollowPlayerPosition, rowVirtualizer]);
246254

247-
if (isLoading) {
255+
if (isLoading || (logEvents.isLoading && spanRows.length === 0)) {
248256
return (
249257
<Stack p="sm" gap="xs">
250258
<Skeleton height={36} />
@@ -285,7 +293,11 @@ export const SessionEventList = ({
285293
dataIndex={virtualItem.index}
286294
isHighlighted={currentEventIndex === virtualItem.index}
287295
ref={rowVirtualizer.measureElement}
288-
onClick={() => onClick(getRowWhere(row.row))}
296+
onClick={() =>
297+
row.open.kind === 'span'
298+
? onClick(getRowWhere(row.open.row))
299+
: logEvents.open(row.open.event)
300+
}
289301
onTimeClick={() => onTimeClick(row.timestamp.getTime())}
290302
/>
291303
</div>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { ComponentProps, use, useEffect } from 'react';
2+
import { SourceKind } from '@hyperdx/common-utils/dist/types';
3+
import { Loader } from '@mantine/core';
4+
5+
import {
6+
DBRowSidePanelInner,
7+
RowSidePanelContext,
8+
} from '@/components/DBRowSidePanel';
9+
import { useSource } from '@/source';
10+
11+
type EventPanelProps = ComponentProps<typeof DBRowSidePanelInner>;
12+
13+
/**
14+
* The session drawer's event view. A browser log event opens on its log
15+
* source; everything else on the trace source passed in `source`.
16+
*/
17+
export default function SessionEventSourcePanel({
18+
sourceId,
19+
...props
20+
}: EventPanelProps & { sourceId?: string }) {
21+
return sourceId ? (
22+
<LogSourceEventPanel {...props} sourceId={sourceId} />
23+
) : (
24+
<DBRowSidePanelInner {...props} />
25+
);
26+
}
27+
28+
function LogSourceEventPanel({
29+
sourceId,
30+
...props
31+
}: EventPanelProps & { sourceId: string }) {
32+
const { data: source, isLoading } = useSource({
33+
id: sourceId,
34+
kinds: [SourceKind.Log],
35+
});
36+
const context = use(RowSidePanelContext);
37+
const { onNavigateToParent } = props;
38+
const isMissing = !isLoading && source == null;
39+
40+
// A link to a deleted source falls back to the session.
41+
useEffect(() => {
42+
if (isMissing) {
43+
onNavigateToParent?.();
44+
}
45+
}, [isMissing, onNavigateToParent]);
46+
47+
if (source == null) {
48+
return <Loader />;
49+
}
50+
return (
51+
<RowSidePanelContext value={{ ...context, source }}>
52+
<DBRowSidePanelInner {...props} source={source} />
53+
</RowSidePanelContext>
54+
);
55+
}

‎packages/app/src/SessionSidePanel.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { notifications } from '@mantine/notifications';
2626
import { IconLink, IconX } from '@tabler/icons-react';
2727

2828
import {
29-
DBRowSidePanelInner,
3029
RowSidePanelContext,
3130
SidePanelErrorFallback,
3231
} from '@/components/DBRowSidePanel';
@@ -46,9 +45,11 @@ import {
4645
copyTextToClipboard,
4746
} from '@/utils/clipboard';
4847
import { parseAsJsonEncoded } from '@/utils/queryParsers';
48+
import type { SessionEventNavigate } from '@/utils/sessionLogEvents';
4949
import { ZIndexContext } from '@/zIndex';
5050

5151
import useSidePanelStack from './hooks/useSidePanelStack';
52+
import SessionEventSourcePanel from './SessionEventSourcePanel';
5253
import { Session } from './sessions';
5354
import SessionSubpanel from './SessionSubpanel';
5455
import { formatDistanceToNowStrictShort } from './utils';
@@ -59,12 +60,15 @@ type SelectedEvent = {
5960
rowId: string;
6061
aliasWith: WithClause[];
6162
sessionId: string;
63+
/** Set for log events; spans live on the trace source. */
64+
sourceId?: string;
6265
};
6366

6467
const sessionEventSchema = z.object({
6568
rowId: z.string(),
6669
aliasWith: z.array(WithClauseSchema),
6770
sessionId: z.string(),
71+
sourceId: z.string().optional(),
6872
});
6973

7074
const sessionEventParser = parseAsJsonEncoded<SelectedEvent>(
@@ -137,11 +141,16 @@ export default function SessionSidePanel({
137141
sidePanelStack.clearTrail();
138142
}, [setSelectedEvent, sidePanelStack]);
139143

140-
const handleEventNavigate = useCallback(
141-
(rowId: string, aliasWith: WithClause[]) => {
144+
const handleEventNavigate = useCallback<SessionEventNavigate>(
145+
(rowId, aliasWith, target) => {
142146
clearSpanSelection();
143147
sidePanelStack.clearTrail();
144-
setSelectedEvent({ rowId, aliasWith, sessionId });
148+
setSelectedEvent({
149+
rowId,
150+
aliasWith,
151+
sessionId,
152+
sourceId: target?.sourceId,
153+
});
145154
},
146155
[clearSpanSelection, setSelectedEvent, sidePanelStack, sessionId],
147156
);
@@ -229,7 +238,8 @@ export default function SessionSidePanel({
229238
/>
230239
)}
231240
>
232-
<DBRowSidePanelInner
241+
<SessionEventSourcePanel
242+
sourceId={selectedEvent.sourceId}
233243
source={traceSource}
234244
rowId={selectedEvent.rowId}
235245
aliasWith={selectedEvent.aliasWith}

‎packages/app/src/SessionSubpanel.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ import {
3030
IconToggleRight,
3131
} from '@tabler/icons-react';
3232

33-
import { RowWhereResult, WithClause } from '@/hooks/useRowWhere';
33+
import { RowWhereResult } from '@/hooks/useRowWhere';
34+
import { useSessionLogEvents } from '@/hooks/useSessionLogEvents';
3435
import type { SessionIdKey } from '@/utils/sessionId';
36+
import type { SessionEventNavigate } from '@/utils/sessionLogEvents';
3537
import { buildSessionEventFilters } from '@/utils/sessions';
3638

3739
import SearchWhereInput from './components/SearchInput/SearchWhereInput';
@@ -234,7 +236,7 @@ export default function SessionSubpanel({
234236
initialTs?: number;
235237
whereLanguage?: SearchConditionLanguage;
236238
onLanguageChange?: (lang: 'sql' | 'lucene') => void;
237-
onEventNavigate?: (rowId: string, aliasWith: WithClause[]) => void;
239+
onEventNavigate?: SessionEventNavigate;
238240
}) {
239241
const [tsQuery, setTsQuery] = useQueryState(
240242
'ts',
@@ -365,6 +367,16 @@ export default function SessionSubpanel({
365367
end,
366368
tab,
367369
});
370+
const logEvents = useSessionLogEvents({
371+
traceSource,
372+
sessionId: rumSessionId,
373+
sessionIdKey: session.sessionIdKey,
374+
serviceName: session.serviceName,
375+
dateRange: eventsDateRange,
376+
tab,
377+
searchedQuery,
378+
onEventNavigate,
379+
});
368380

369381
const [playerFullWidth, setPlayerFullWidth] = useState(false);
370382

@@ -485,6 +497,7 @@ export default function SessionSubpanel({
485497
eventsFollowPlayerPosition={eventsFollowPlayerPosition}
486498
aliasMap={aliasMap}
487499
queriedConfig={eventsConfig}
500+
logEvents={logEvents}
488501
onClick={onSessionEventClick}
489502
focus={focus}
490503
onTimeClick={onSessionEventTimeClick}
@@ -528,6 +541,7 @@ export default function SessionSubpanel({
528541
setFocus={setFocus}
529542
playbackRange={playbackRange}
530543
queriedConfig={eventsConfig}
544+
logEvents={logEvents.events}
531545
/>
532546
)}
533547
</div>

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
getRowLookupWindow,
5858
resolveRowTimestampAnchor,
5959
} from '@/utils/rowTimestamps';
60+
import type { SessionEventNavigate } from '@/utils/sessionLogEvents';
6061
import { useZIndex, ZIndexContext } from '@/zIndex';
6162

6263
import ServiceMapSidePanel from './ServiceMap/ServiceMapSidePanel';
@@ -618,19 +619,37 @@ export const DBRowSidePanelInner = ({
618619
return clauses.length > 0 ? clauses.join(' AND ') : undefined;
619620
}, [traceIdExpression, traceId, spanIdExpression, spanId]);
620621

621-
const handleSessionEventNavigate = useCallback(
622-
(rowId: string, aliasWith: WithClause[]) => {
623-
if (traceSourceData) {
622+
const handleSessionEventNavigate = useCallback<SessionEventNavigate>(
623+
(rowId, aliasWith, target) => {
624+
const label = mainContent || 'Session Replay';
625+
if (target?.sourceId === source.id) {
626+
handleNavigateToRow(rowId, aliasWith, label, SourceKind.Log);
627+
} else if (target != null) {
628+
handleSourceStackPush({
629+
sourceId: target.sourceId,
630+
rowId,
631+
aliasWith,
632+
label,
633+
sourceKind: SourceKind.Log,
634+
focusTimestamp: target.focusTimestamp,
635+
});
636+
} else if (traceSourceData) {
624637
handleSourceStackPush({
625638
sourceId: traceSourceData.id,
626639
rowId,
627640
aliasWith,
628-
label: mainContent || 'Session Replay',
641+
label,
629642
sourceKind: traceSourceData.kind as SourceKind,
630643
});
631644
}
632645
},
633-
[traceSourceData, handleSourceStackPush, mainContent],
646+
[
647+
traceSourceData,
648+
source.id,
649+
handleNavigateToRow,
650+
handleSourceStackPush,
651+
mainContent,
652+
],
634653
);
635654

636655
const handleTraceLogNavigate = useCallback(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { isTraceSource, SourceKind } from '@hyperdx/common-utils/dist/types';
44
import { Loader } from '@mantine/core';
55

66
import useFieldExpressionGenerator from '@/hooks/useFieldExpressionGenerator';
7-
import { WithClause } from '@/hooks/useRowWhere';
87
import SessionSubpanel from '@/SessionSubpanel';
98
import { useSource } from '@/source';
109
import { SessionIdKey, traceSessionIdColumns } from '@/utils/sessionId';
10+
import type { SessionEventNavigate } from '@/utils/sessionLogEvents';
1111

1212
import { useEventsData } from './DBTraceWaterfallChart';
1313

@@ -124,7 +124,7 @@ export const DBSessionPanel = ({
124124
dateRange: [Date, Date];
125125
focusDate: Date;
126126
serviceName?: string;
127-
onEventNavigate?: (rowId: string, aliasWith: WithClause[]) => void;
127+
onEventNavigate?: SessionEventNavigate;
128128
}) => {
129129
const { data: traceSource } = useSource({
130130
id: traceSourceId,

0 commit comments

Comments
 (0)