Skip to content

Commit

Permalink
Include search results based on replay table as well as events table (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeShi42 authored Jun 18, 2024
1 parent e88f865 commit 4d750fa
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/api/src/clickhouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,10 @@ export const getSessions = async ({
],
);

// Filter by the rrweb table if there are any recordings for the session
// because session_id is the sort key prefix, it'll be a quick lookup operation
// Otherwise we'll want to filter on events in case recordings were
// disabled but we still have significant span events
// Filter by either a record init span, or a visibility span
// 1. Record init is emitted on SDK initialization and should only happen
// if there is an actual recording being done for the session (ex. no background sessions)
Expand All @@ -2382,6 +2386,12 @@ export const getSessions = async ({
const sessionsWithRecordingsQuery = SqlString.format(
`WITH sessions AS (${sessionsWithSearchQuery}),
sessionIdsWithRecordings AS (
SELECT DISTINCT session_id as sessionId
FROM ??
WHERE (session_id IN (SELECT sessions.sessionId FROM sessions))
AND (?)
),
sessionIdsWithUserActivity AS (
SELECT DISTINCT _rum_session_id as sessionId
FROM ??
WHERE (span_name='record init' OR span_name='visibility')
Expand All @@ -2392,8 +2402,12 @@ SELECT *
FROM sessions
WHERE sessions.sessionId IN (
SELECT sessionIdsWithRecordings.sessionId FROM sessionIdsWithRecordings
) OR sessions.sessionId IN (
SELECT sessionIdsWithUserActivity.sessionId FROM sessionIdsWithUserActivity
)`,
[
`default.${TableName.Rrweb}`,
SqlString.raw(SearchQueryBuilder.timestampInBetween(startTime, endTime)),
tableName,
SqlString.raw(SearchQueryBuilder.timestampInBetween(startTime, endTime)),
],
Expand Down

0 comments on commit 4d750fa

Please sign in to comment.