Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/session-replay-otel-session-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

feat: List and play session replays from OpenTelemetry browser SDKs that send `session.id`
5 changes: 4 additions & 1 deletion packages/app/src/DOMPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
createRrwebChunkAssembler,
RRWebStreamRow,
} from '@/utils/rrwebChunkAssembler';
import type { SessionIdKey } from '@/utils/sessionId';

import { FieldExpressionGenerator } from './hooks/useFieldExpressionGenerator';

Expand Down Expand Up @@ -101,7 +102,7 @@ const URLHoverCard = memo(({ url }: { url: string }) => {
});

export default function DOMPlayer({
config: { dateRange, serviceName, sessionId, sourceId },
config: { dateRange, serviceName, sessionId, sessionIdKey, sourceId },
focus,
setPlayerTime,
playerState,
Expand All @@ -119,6 +120,7 @@ export default function DOMPlayer({
dateRange: [Date, Date];
serviceName: string;
sessionId: string;
sessionIdKey?: SessionIdKey;
sourceId: string;
};
focus: { ts: number; setBy: string } | undefined;
Expand Down Expand Up @@ -247,6 +249,7 @@ export default function DOMPlayer({
{
serviceName,
sessionId,
sessionIdKey,
sourceId,
startDate: dateRange[0],
endDate: dateRange[1],
Expand Down
12 changes: 7 additions & 5 deletions packages/app/src/Playbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { keepPreviousData } from '@tanstack/react-query';

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

import { SessionRow, sessionRowSchema } from './utils/sessions';
import {
getSessionRowHttp,
SessionRow,
sessionRowSchema,
} from './utils/sessions';
import type { PlaybarMarker } from './PlaybarSlider';
import { PlaybarSlider } from './PlaybarSlider';
import { getShortUrl } from './utils';
Expand Down Expand Up @@ -71,9 +75,7 @@ export default function Playbar({

const errorMessage = event['error.message'] ?? '';

const url = event['http.url'] ?? '';
const statusCode = Number(event['http.status_code'] ?? '');
const method = event['http.method'] ?? '';
const { url, statusCode, label } = getSessionRowHttp(event);
const shortUrl = getShortUrl(url);

const isNavigation =
Expand All @@ -96,7 +98,7 @@ export default function Playbar({
description: isNavigation
? `Navigated to ${shortLocationHref}`
: url.length > 0
? `${statusCode} ${method}${url.length > 0 ? ` ${shortUrl}` : ''}`
? `${label} ${shortUrl}`
: errorMessage != null && errorMessage.length > 0
? errorMessage
: spanName === 'intercom.onShow'
Expand Down
12 changes: 7 additions & 5 deletions packages/app/src/SessionEventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { useVirtualizer } from '@tanstack/react-virtual';
import useRowWhere, { RowWhereResult } from '@/hooks/useRowWhere';

import { useQueriedChartConfig } from './hooks/useChartConfig';
import { SessionRow, sessionRowSchema } from './utils/sessions';
import {
getSessionRowHttp,
SessionRow,
sessionRowSchema,
} from './utils/sessions';
import { useFormatTime } from './useFormatTime';
import { formatmmss, getShortUrl } from './utils';

Expand Down Expand Up @@ -135,9 +139,7 @@ export const SessionEventList = ({
const startOffset = new Date(timestamp).getTime();
const endOffset = new Date(startOffset).getTime() + durationInMs;

const url = event['http.url'] ?? '';
const statusCode = Number(event['http.status_code'] ?? '');
const method = event['http.method'] ?? '';
const { url, method, statusCode, label } = getSessionRowHttp(event);
const shortUrl = getShortUrl(url);

const isNetworkRequest =
Expand Down Expand Up @@ -186,7 +188,7 @@ export const SessionEventList = ({
: spanName === 'console.warn'
? 'console.warn'
: url.length > 0
? `${statusCode} ${method}`
? label

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 minor — Spans with url.full but no method or status code now show an empty title in All Events, and Playbar descriptions start with a stray space

The All Events filter now matches ${attrs}.url.full:* (utils/sessions.ts, line ~98). OTel document-load documentFetch/resourceFetch spans carry url.full but no http.request.method or status code. For those spans getSessionRowHttp returns label: '', so the url.length > 0 ? label branch renders a blank title, and Playbar renders `${label} ${shortUrl}` as " /path". Before this PR, the old filter required http.status_code:*, so these spans never appeared. Fix: fall back to the span name when label is empty, e.g. url.length > 0 ? label || spanName, and do the same in Playbar ([label, shortUrl].filter(Boolean).join(' ')). Alternatively, narrow the filter to url.full:* AND http.request.method:*.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

: spanName === 'intercom.onShow'
? 'Intercom Chat Opened'
: isCustomEvent
Expand Down
67 changes: 27 additions & 40 deletions packages/app/src/SessionSubpanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
} from '@tabler/icons-react';

import { RowWhereResult, WithClause } from '@/hooks/useRowWhere';
import type { SessionIdKey } from '@/utils/sessionId';
import { buildSessionEventFilters } from '@/utils/sessions';

import SearchWhereInput from './components/SearchInput/SearchWhereInput';
import useFieldExpressionGenerator from './hooks/useFieldExpressionGenerator';
Expand All @@ -47,6 +49,7 @@ const MemoPlaybar = memo(Playbar);
function useSessionChartConfigs({
traceSource,
rumSessionId,
sessionIdKey,
where,
whereLanguage,
start,
Expand All @@ -55,6 +58,7 @@ function useSessionChartConfigs({
}: {
traceSource: TTraceSource;
rumSessionId: string;
sessionIdKey?: SessionIdKey;
where: string;
whereLanguage?: SearchConditionLanguage;
start: Date;
Expand Down Expand Up @@ -96,6 +100,15 @@ function useSessionChartConfigs({
valueExpression: `${getTraceSourceFieldExpression(traceSource.eventAttributesExpression ?? 'SpanAttributes', 'http.url')}`,
alias: 'http.url',
},
...['url.full', 'http.request.method', 'http.response.status_code'].map(
key => ({
valueExpression: getTraceSourceFieldExpression(
traceSource.eventAttributesExpression ?? 'SpanAttributes',
key,
),
alias: key,
}),
),
{
// Using toString here because Javascript does not have the precision to accurately represent this
valueExpression: `toString(cityHash64(${traceSource.traceIdExpression}, ${traceSource.parentSpanIdExpression}, ${traceSource.spanIdExpression}))`,
Expand Down Expand Up @@ -140,43 +153,18 @@ function useSessionChartConfigs({
];
}, [traceSource, getTraceSourceFieldExpression]);

// Events shown in the highlighted tab
const highlightedEventsFilter = useMemo(
() => ({
type: 'lucene' as const,
condition: `${traceSource.resourceAttributesExpression}.rum.sessionId:"${rumSessionId}"
AND (
${traceSource.eventAttributesExpression}.http.status_code:>299
OR ${traceSource.eventAttributesExpression}.component:"error"
OR ${traceSource.spanNameExpression}:"routeChange"
OR ${traceSource.spanNameExpression}:"documentLoad"
OR ${traceSource.spanNameExpression}:"intercom.onShow"
OR ScopeName:"custom-action"
)`,
}),
[traceSource, rumSessionId],
const eventFilters = useMemo(
() =>
buildSessionEventFilters({
traceSource,
sessionId: rumSessionId,
sessionIdKey,
}),
[traceSource, rumSessionId, sessionIdKey],
);

const allEventsFilter = useMemo(() => {
if (!getTraceSourceFieldExpression) return undefined;
return {
type: 'lucene' as const,
condition: `${traceSource.resourceAttributesExpression}.rum.sessionId:"${rumSessionId}"
AND (
${traceSource.eventAttributesExpression}.http.status_code:*
OR ${traceSource.eventAttributesExpression}.component:"console"
OR ${traceSource.eventAttributesExpression}.component:"error"
OR ${traceSource.spanNameExpression}:"routeChange"
OR ${traceSource.spanNameExpression}:"documentLoad"
OR ${traceSource.spanNameExpression}:"intercom.onShow"
OR ScopeName:"custom-action"
)`,
};
}, [traceSource, rumSessionId, getTraceSourceFieldExpression]);

const eventsConfig = useMemo<ChartConfigWithOptDateRange | undefined>(() => {
if (!getTraceSourceFieldExpression || !select || !allEventsFilter)
return undefined;
if (!getTraceSourceFieldExpression || !select) return undefined;
return {
select: select,
from: traceSource.from,
Expand All @@ -193,9 +181,7 @@ function useSessionChartConfigs({
limit: 4000,
offset: 0,
},
filters: [
tab === 'highlighted' ? highlightedEventsFilter : allEventsFilter,
],
filters: eventFilters[tab === 'highlighted' ? 'highlighted' : 'all'],
};
}, [
select,
Expand All @@ -205,8 +191,7 @@ function useSessionChartConfigs({
where,
whereLanguage,
tab,
highlightedEventsFilter,
allEventsFilter,
eventFilters,
getTraceSourceFieldExpression,
]);

Expand Down Expand Up @@ -242,7 +227,7 @@ export default function SessionSubpanel({
}: {
traceSource: TTraceSource;
sessionSource: TSessionSource;
session: { serviceName: string };
session: { serviceName: string; sessionIdKey?: SessionIdKey };
rumSessionId: string;
start: Date;
end: Date;
Expand Down Expand Up @@ -373,6 +358,7 @@ export default function SessionSubpanel({
const { eventsConfig, aliasMap } = useSessionChartConfigs({
traceSource,
rumSessionId,
sessionIdKey: session.sessionIdKey,
where: searchedQuery,
whereLanguage,
start,
Expand Down Expand Up @@ -519,6 +505,7 @@ export default function SessionSubpanel({
serviceName: session.serviceName,
sourceId: sessionSource.id,
sessionId: rumSessionId,
sessionIdKey: session.sessionIdKey,
dateRange: [start, end],
}}
playerSpeed={playerSpeed}
Expand Down
17 changes: 17 additions & 0 deletions packages/app/src/__tests__/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ describe('buildRRWebStreamChartConfig', () => {
expect(config.dateRange).toEqual([new Date(1000), new Date(2000)]);
expect(config.limit).toEqual({ limit: 1000000, offset: 0 });
});

it('looks up OTel sessions by session.id', () => {
const otelConfig = buildRRWebStreamChartConfig({
source: config,
serviceName: 'my-service',
sessionId: 'session-1',
sessionIdKey: 'session.id',
startDate: new Date(1000),
endDate: new Date(2000),
limit: 1000000,
offset: 0,
getSessionSourceFieldExpression,
});
expect(otelConfig.where).toBe(
'ServiceName:"my-service" AND LogAttributes.session.id:"session-1"',
);
});
});

describe('fetchServiceScopeFilters', () => {
Expand Down
Loading
Loading