Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(replay): classify mobile recordings during ingestion (#96389)

Manoel Aranda Netofbb1a314f87f
diff --git a/docs/internal/mobile-replay-capture-mode.md b/docs/internal/mobile-replay-capture-mode.md
new file mode 100644
index 000000000000..f59b13c45f1c
--- /dev/null
+++ b/docs/internal/mobile-replay-capture-mode.md
@@ -0,0 +1,74 @@
+# Mobile replay capture mode
+
+Replay ingestion stores `snapshot_mode` in ClickHouse recording metadata so recordings can be counted by rendering mode without downloading replay blobs.
+This field only applies to events with `$snapshot_source = 'mobile'`.
+
+## Classification
+
+The first valid visual wireframe identifies the recording mode:
+
+- `type = 'screenshot'`: `screenshot`.
+- Any other or missing `type`: `wireframe`.
+- No visual wireframe found: `NULL`.
+
+A wireframe must be an object with a finite numeric `id`.
+The classifier checks full snapshots at `data.wireframes` and incremental mutations at `data.adds[*].wireframe` and `data.updates[*].wireframe`.
+It ignores metadata, touch, network, console, and removal-only events.
+Base64 image data does not identify screenshot mode because wireframe-mode image views can also contain it.
+
+A recording uses one mode throughout its lifetime.
+The recorder stops inspecting wireframes once it identifies the mode for its in-memory storage block.
+Each new block can identify the mode independently, without a shared cache or a ClickHouse lookup.
+ClickHouse stores `AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))` and retains the first non-null mode across blocks.
+Blocks without visual evidence cannot overwrite a known mode.
+
+## Querying daily recording counts
+
+Use `argMinMerge(snapshot_mode)` on the physical ClickHouse `session_replay_events` table.
+The column is not exposed through the HogQL schema.
+Group by both `team_id` and `session_id` before counting; one recording can have multiple rows or span midnight.
+
+This example counts retained, non-deleted mobile recordings by their first recorded timestamp in UTC for one project.
+Replace `1` with the project ID.
+The date filter runs after session aggregation so a recording that crosses the reporting boundary keeps its original start date.
+
+```sql
+SELECT
+ toDate(started_at, 'UTC') AS day,
+ coalesce(mode, 'unknown') AS snapshot_mode,
+ count() AS recordings
+FROM
+(
+ SELECT
+ team_id,
+ session_id,
+ min(min_first_timestamp) AS started_at,
+ argMinMerge(snapshot_source) AS source,
+ argMinMerge(snapshot_mode) AS mode,
+ max(is_deleted) AS deleted
+ FROM session_replay_events
+ WHERE team_id = 1
+ GROUP BY team_id, session_id
+)
+WHERE source = 'mobile'
+ AND deleted = 0
+ AND started_at >= toStartOfDay(now('UTC')) - INTERVAL 7 DAY
+ AND started_at < toStartOfDay(now('UTC'))
+GROUP BY day, snapshot_mode
+ORDER BY day, snapshot_mode
+```
+
+This query scans retained metadata for the selected project.
+For fleet-wide reporting, remove the project filter only after checking query cost.
+Do not filter out null modes before aggregating sessions: that can move the apparent recording start to a later block.
+Keep the `unknown` count visible to distinguish missing classifications from wireframe recordings.
+
+## Deployment and historical data
+
+Ship the ClickHouse migration separately and apply it before deploying the ingestion change.
+The migration updates the sharded, read, and writable tables, plus the MSK or WarpStream ingestion path used by the environment.
+Old producers can omit the nullable field during rollout.
+
+Only newly ingested visual snapshots populate the mode.
+Historical recordings remain unknown unless new blocks identify their mode or retained replay blobs are classified and backfilled separately.
+The anonymized ML mirror uses separate metadata storage and is outside this ClickHouse reporting path.
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts b/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts
index 97157328b646..1da601ea760a 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/rrweb-types.ts
@@ -29,6 +29,46 @@ export enum RRWebEventSource {
AdoptedStyleSheet = 15,
}
+export type SnapshotMode = 'screenshot' | 'wireframe'
+
+export function snapshotModeFrom(event: SnapshotEvent): SnapshotMode | null {
+ const data = event.data as { source?: number; wireframes?: unknown; adds?: unknown; updates?: unknown } | undefined
+ if (event.type === RRWebEventType.FullSnapshot && Array.isArray(data?.wireframes)) {
+ for (const wireframe of data.wireframes) {
+ const mode = modeFromWireframe(wireframe)
+ if (mode) {
+ return mode
+ }
+ }
+ }
+
+ if (event.type === RRWebEventType.IncrementalSnapshot && data?.source === RRWebEventSource.Mutation) {
+ for (const mutations of [data.adds, data.updates]) {
+ if (!Array.isArray(mutations)) {
+ continue
+ }
+ for (const mutation of mutations) {
+ const mode = modeFromWireframe(mutation?.wireframe)
+ if (mode) {
+ return mode
+ }
+ }
+ }
+ }
+ return null
+}
+
+function modeFromWireframe(value: unknown): SnapshotMode | null {
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
+ return null
+ }
+ const wireframe = value as { id?: unknown; type?: unknown }
+ if (typeof wireframe.id !== 'number' || !Number.isFinite(wireframe.id)) {
+ return null
+ }
+ return wireframe.type === 'screenshot' ? 'screenshot' : 'wireframe'
+}
+
export enum MouseInteractions {
MouseUp = 0,
MouseDown = 1,
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.test.ts
index af0a6958ab2b..72b5cc95d3fa 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.test.ts
@@ -107,6 +107,7 @@ export class SnappySessionRecorderMock {
messageCount: 0,
snapshotSource: null,
snapshotLibrary: null,
+ snapshotMode: null,
batchId: this.batchId,
}
}
@@ -1338,8 +1339,9 @@ describe('SessionBatchRecorder', () => {
activeMilliseconds: 8000,
size: 1024,
messageCount: 15,
- snapshotSource: 'web',
- snapshotLibrary: '[email protected]',
+ snapshotSource: 'mobile',
+ snapshotLibrary: 'posthog-android',
+ snapshotMode: 'screenshot',
batchId: 'test_batch_id',
})
@@ -1400,8 +1402,9 @@ describe('SessionBatchRecorder', () => {
consoleErrorCount: 2,
size: 1024,
messageCount: 15,
- snapshotSource: 'web',
- snapshotLibrary: '[email protected]',
+ snapshotSource: 'mobile',
+ snapshotLibrary: 'posthog-android',
+ snapshotMode: 'screenshot',
}),
])
})
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.ts
index cb4ab80e3adc..72b92bb89889 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/session-batch-recorder.ts
@@ -277,6 +277,7 @@ export class SessionBatchRecorder {
messageCount,
snapshotSource,
snapshotLibrary,
+ snapshotMode,
replayIndexEntries,
replayIndexTruncated,
batchId,
@@ -330,6 +331,7 @@ export class SessionBatchRecorder {
messageCount,
snapshotSource,
snapshotLibrary,
+ snapshotMode,
replayIndexEntries,
replayIndexTruncated,
batchId,
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.test.ts
index 643b000ad25c..34f57e0a307f 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.test.ts
@@ -989,6 +989,67 @@ describe('SnappySessionRecorder', () => {
})
})
+ describe('Snapshot mode tracking', () => {
+ it.each([
+ ['full screenshot', 2, { wireframes: [{ id: 1, type: 'screenshot' }] }, 'screenshot'],
+ ['full text', 2, { wireframes: [{ id: 1, type: 'text' }] }, 'wireframe'],
+ ['untyped container', 2, { wireframes: [{ id: 1 }] }, 'wireframe'],
+ ['null type', 2, { wireframes: [{ id: 1, type: null }] }, 'wireframe'],
+ ['image with base64', 2, { wireframes: [{ id: 1, type: 'image', base64: 'fake-image' }] }, 'wireframe'],
+ [
+ 'incremental screenshot add',
+ 3,
+ { source: 0, adds: [{ wireframe: { id: 1, type: 'screenshot' } }] },
+ 'screenshot',
+ ],
+ [
+ 'incremental screenshot update',
+ 3,
+ { source: 0, updates: [{ wireframe: { id: 1, type: 'screenshot' } }] },
+ 'screenshot',
+ ],
+ ['incremental wireframe update', 3, { source: 0, updates: [{ wireframe: { id: 1 } }] }, 'wireframe'],
+ ['meta', 4, { width: 100, height: 200 }, null],
+ ['touch', 3, { source: 2, type: 7, id: 1 }, null],
+ ['removal', 3, { source: 0, removes: [{ id: 1 }] }, null],
+ ['empty full snapshot', 2, { wireframes: [] }, null],
+ ['malformed wireframes', 2, { wireframes: [null, {}, 'invalid'] }, null],
+ ['web DOM mutation', 3, { source: 0, adds: [{ node: { id: 1, type: 2 } }] }, null],
+ ])('classifies %s', async (_name, type, data, expectedMode) => {
+ const message = createMessage('window1', [{ type, data, timestamp: 1000 }])
+ message.snapshot_source = 'mobile'
+ recorder.recordMessage(message)
+ expect((await recorder.end()).snapshotMode).toBe(expectedMode)
+ })
+
+ it.each(['web', null, 'Mobile'])('does not classify source %s', async (source) => {
+ const message = createMessage('window1', [
+ { type: 2, data: { wireframes: [{ id: 1, type: 'screenshot' }] }, timestamp: 1000 },
+ ])
+ message.snapshot_source = source
+ recorder.recordMessage(message)
+ expect((await recorder.end()).snapshotMode).toBeNull()
+ })
+
+ it('waits for a visual snapshot in a later message and keeps its classification', async () => {
+ const events = [
+ { type: 4, data: { width: 100, height: 200 }, timestamp: 1000 },
+ {
+ type: 3,
+ data: { source: 0, updates: [{ wireframe: { id: 1, type: 'screenshot' } }] },
+ timestamp: 2000,
+ },
+ { type: 3, data: { source: 2, type: 7, id: 1 }, timestamp: 3000 },
+ ]
+ for (const event of events) {
+ const message = createMessage('window1', [event])
+ message.snapshot_source = 'mobile'
+ recorder.recordMessage(message)
+ }
+ expect((await recorder.end()).snapshotMode).toBe('screenshot')
+ })
+ })
+
describe('Buffer size reporting', () => {
it('should report the uncompressed buffer size', async () => {
// Create a message with a known event
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.ts b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.ts
index 6043aae849c5..a1a9a5ac89f8 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/sessions/snappy-session-recorder.ts
@@ -10,7 +10,14 @@ import {
PRE_SERIALIZED_FLAG_MOUSE_ACTIVITY,
ParsedMessageData,
} from '~/ingestion/pipelines/sessionreplay/kafka/types'
-import { hrefFrom, isClick, isKeypress, isMouseActivity } from '~/ingestion/pipelines/sessionreplay/rrweb-types'
+import {
+ SnapshotMode,
+ hrefFrom,
+ isClick,
+ isKeypress,
+ isMouseActivity,
+ snapshotModeFrom,
+} from '~/ingestion/pipelines/sessionreplay/rrweb-types'
import {
SegmentationEvent,
activeMillisecondsFromSegmentationEvents,
@@ -52,6 +59,8 @@ export interface EndResult {
snapshotSource: string | null
/** Library used for the snapshot */
snapshotLibrary: string | null
+ /** Only applies when snapshotSource is 'mobile'; null until a visual snapshot identifies the mode. */
+ snapshotMode: SnapshotMode | null
/** ID of the batch this session belongs to */
batchId: string
replayIndexEntries?: ReplayIndexEntry[]
@@ -97,6 +106,7 @@ export class SnappySessionRecorder {
private messageCount: number = 0
private snapshotSource: string | null = null
private snapshotLibrary: string | null = null
+ private snapshotMode: SnapshotMode | null = null
private segmentationEvents: SegmentationEvent[] = []
private droppedUrlsCount: number = 0
private replayIndexEntries: ReplayIndexEntry[] = []
@@ -154,6 +164,9 @@ export class SnappySessionRecorder {
for (const [windowId, events] of Object.entries(message.eventsByWindowId)) {
for (const event of events) {
+ if (this.snapshotMode === null && message.snapshot_source === 'mobile') {
+ this.snapshotMode = snapshotModeFrom(event)
+ }
const serializedLine = JSON.stringify([windowId, event]) + '\n'
const chunk = Buffer.from(serializedLine)
this.uncompressedChunks.push(chunk)
@@ -320,6 +333,7 @@ export class SnappySessionRecorder {
messageCount: this.messageCount,
snapshotSource: this.snapshotSource,
snapshotLibrary: this.snapshotLibrary,
+ snapshotMode: this.snapshotMode,
batchId: this.batchId,
...(this.replayIndexEntries.length ? { replayIndexEntries: this.replayIndexEntries } : {}),
...(this.replayIndexTruncated ? { replayIndexTruncated: true } : {}),
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-block-metadata.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-block-metadata.ts
index dcb3fcde9471..3f465534386a 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-block-metadata.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-block-metadata.ts
@@ -1,5 +1,7 @@
import { DateTime } from 'luxon'
+import { SnapshotMode } from '~/ingestion/pipelines/sessionreplay/rrweb-types'
+
import { ReplayIndexEntry } from './replay-index-entry'
/**
@@ -32,6 +34,7 @@ export function createNoopBlockMetadata(sessionId: string, teamId: number): Sess
messageCount: 0,
snapshotSource: null,
snapshotLibrary: null,
+ snapshotMode: null,
retentionPeriodDays: null,
isDeleted: false,
}
@@ -88,6 +91,8 @@ export interface SessionBlockMetadata {
snapshotSource: string | null
/** Library used for the snapshot */
snapshotLibrary: string | null
+ /** Only applies when snapshotSource is 'mobile'; null until a visual snapshot identifies the mode. */
+ snapshotMode: SnapshotMode | null
/** Retention period for this session block */
retentionPeriodDays: number | null
/** Whether this recording has been deleted */
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.test.ts
index 6bbcd507c6ce..bfee0defa3b5 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.test.ts
@@ -25,183 +25,192 @@ describe('SessionMetadataStore', () => {
store = new SessionMetadataStore(mockOutputs)
})
- it('should queue events to kafka with correct data', async () => {
- const blocks = [
- {
- sessionId: 'session123',
- teamId: 1,
- distinctId: 'user1',
- batchId: 'batch123',
- blockLength: 100,
- eventCount: 25,
- startDateTime: DateTime.fromISO('2025-01-01T10:00:00.000Z'),
- endDateTime: DateTime.fromISO('2025-01-01T10:00:02.000Z'),
- blockUrl: 's3://bucket/file1?range=bytes=0-99',
- firstUrl: 'https://example.com',
- urls: ['https://example.com', 'https://example.com/page2'],
- clickCount: 5,
- keypressCount: 10,
- mouseActivityCount: 15,
- activeMilliseconds: 2000,
- consoleLogCount: 3,
- consoleWarnCount: 2,
- consoleErrorCount: 1,
- size: 1024,
- messageCount: 50,
- snapshotSource: 'web',
- snapshotLibrary: '[email protected]',
- retentionPeriodDays: 30,
- isDeleted: false,
- },
- {
- sessionId: 'different456',
- teamId: 2,
- distinctId: 'user2',
- batchId: 'batch123',
- blockLength: 150,
- eventCount: 15,
- startDateTime: DateTime.fromISO('2025-01-01T10:00:01.500Z'),
- endDateTime: DateTime.fromISO('2025-01-01T10:00:03.500Z'),
- blockUrl: 's3://bucket/file1?range=bytes=100-249',
- firstUrl: 'https://example.com/different',
- urls: ['https://example.com/different'],
- clickCount: 2,
- keypressCount: 5,
- mouseActivityCount: 8,
- activeMilliseconds: 1500,
- consoleLogCount: 1,
- consoleWarnCount: 1,
- consoleErrorCount: 0,
- size: 512,
- messageCount: 30,
- snapshotSource: 'web',
- snapshotLibrary: '[email protected]',
- retentionPeriodDays: 30,
- isDeleted: false,
- },
- {
- sessionId: 'session123',
- teamId: 1,
- distinctId: 'user1',
- batchId: 'batch123',
- blockLength: 200,
- eventCount: 35,
- startDateTime: DateTime.fromISO('2025-01-01T10:00:03.000Z'),
- endDateTime: DateTime.fromISO('2025-01-01T10:00:05.000Z'),
- blockUrl: 's3://bucket/file1?range=bytes=250-449',
- firstUrl: 'https://example.com',
- urls: ['https://example.com', 'https://example.com/page3'],
- clickCount: 7,
- keypressCount: 15,
- mouseActivityCount: 20,
- activeMilliseconds: 2500,
- consoleLogCount: 4,
- consoleWarnCount: 1,
- consoleErrorCount: 2,
- size: 2048,
- messageCount: 70,
- snapshotSource: 'web',
- snapshotLibrary: '[email protected]',
- retentionPeriodDays: 30,
- isDeleted: false,
- },
- ]
+ it.each(['screenshot', 'wireframe', null] as const)(
+ 'should queue events to kafka with snapshot mode %s',
+ async (snapshotMode) => {
+ const blocks = [
+ {
+ sessionId: 'session123',
+ teamId: 1,
+ distinctId: 'user1',
+ batchId: 'batch123',
+ blockLength: 100,
+ eventCount: 25,
+ startDateTime: DateTime.fromISO('2025-01-01T10:00:00.000Z'),
+ endDateTime: DateTime.fromISO('2025-01-01T10:00:02.000Z'),
+ blockUrl: 's3://bucket/file1?range=bytes=0-99',
+ firstUrl: 'https://example.com',
+ urls: ['https://example.com', 'https://example.com/page2'],
+ clickCount: 5,
+ keypressCount: 10,
+ mouseActivityCount: 15,
+ activeMilliseconds: 2000,
+ consoleLogCount: 3,
+ consoleWarnCount: 2,
+ consoleErrorCount: 1,
+ size: 1024,
+ messageCount: 50,
+ snapshotSource: 'mobile',
+ snapshotLibrary: 'posthog-ios',
+ snapshotMode,
+ retentionPeriodDays: 30,
+ isDeleted: false,
+ },
+ {
+ sessionId: 'different456',
+ teamId: 2,
+ distinctId: 'user2',
+ batchId: 'batch123',
+ blockLength: 150,
+ eventCount: 15,
+ snapshotMode: null,
+ startDateTime: DateTime.fromISO('2025-01-01T10:00:01.500Z'),
+ endDateTime: DateTime.fromISO('2025-01-01T10:00:03.500Z'),
+ blockUrl: 's3://bucket/file1?range=bytes=100-249',
+ firstUrl: 'https://example.com/different',
+ urls: ['https://example.com/different'],
+ clickCount: 2,
+ keypressCount: 5,
+ mouseActivityCount: 8,
+ activeMilliseconds: 1500,
+ consoleLogCount: 1,
+ consoleWarnCount: 1,
+ consoleErrorCount: 0,
+ size: 512,
+ messageCount: 30,
+ snapshotSource: 'web',
+ snapshotLibrary: '[email protected]',
+ retentionPeriodDays: 30,
+ isDeleted: false,
+ },
+ {
+ sessionId: 'session123',
+ teamId: 1,
+ distinctId: 'user1',
+ batchId: 'batch123',
+ blockLength: 200,
+ eventCount: 35,
+ startDateTime: DateTime.fromISO('2025-01-01T10:00:03.000Z'),
+ endDateTime: DateTime.fromISO('2025-01-01T10:00:05.000Z'),
+ blockUrl: 's3://bucket/file1?range=bytes=250-449',
+ firstUrl: 'https://example.com',
+ urls: ['https://example.com', 'https://example.com/page3'],
+ clickCount: 7,
+ keypressCount: 15,
+ mouseActivityCount: 20,
+ activeMilliseconds: 2500,
+ consoleLogCount: 4,
+ consoleWarnCount: 1,
+ consoleErrorCount: 2,
+ size: 2048,
+ messageCount: 70,
+ snapshotSource: 'mobile',
+ snapshotLibrary: 'posthog-ios',
+ snapshotMode,
+ retentionPeriodDays: 30,
+ isDeleted: false,
+ },
+ ]
- await store.storeSessionBlocks(blocks)
+ await store.storeSessionBlocks(blocks)
- expect(mockOutputs.queueMessages).toHaveBeenCalledTimes(1)
- const [outputName, queuedMessages] = mockOutputs.queueMessages.mock.calls[0]
- expect(outputName).toBe(REPLAY_EVENTS_OUTPUT)
- const parsedEvents = queuedMessages.map((msg) => parseValue(msg.value))
+ expect(mockOutputs.queueMessages).toHaveBeenCalledTimes(1)
+ const [outputName, queuedMessages] = mockOutputs.queueMessages.mock.calls[0]
+ expect(outputName).toBe(REPLAY_EVENTS_OUTPUT)
+ const parsedEvents = queuedMessages.map((msg) => parseValue(msg.value))
- expect(parsedEvents).toMatchObject([
- {
- uuid: expect.any(String),
- session_id: 'session123',
- team_id: 1,
- distinct_id: 'user1',
- batch_id: 'batch123',
- first_timestamp: '2025-01-01 10:00:00.000',
- last_timestamp: '2025-01-01 10:00:02.000',
- block_url: 's3://bucket/file1?range=bytes=0-99',
- first_url: 'https://example.com',
- urls: ['https://example.com', 'https://example.com/page2'],
- click_count: 5,
- keypress_count: 10,
- mouse_activity_count: 15,
- active_milliseconds: 2000,
- console_log_count: 3,
- console_warn_count: 2,
- console_error_count: 1,
- size: 1024,
- message_count: 50,
- snapshot_source: 'web',
- snapshot_library: '[email protected]',
- event_count: 25,
- retention_period_days: 30,
- is_deleted: 0,
- },
- {
- uuid: expect.any(String),
- session_id: 'different456',
- team_id: 2,
- distinct_id: 'user2',
- batch_id: 'batch123',
- first_timestamp: '2025-01-01 10:00:01.500',
- last_timestamp: '2025-01-01 10:00:03.500',
- block_url: 's3://bucket/file1?range=bytes=100-249',
- first_url: 'https://example.com/different',
- urls: ['https://example.com/different'],
- click_count: 2,
- keypress_count: 5,
- mouse_activity_count: 8,
- active_milliseconds: 1500,
- console_log_count: 1,
- console_warn_count: 1,
- console_error_count: 0,
- size: 512,
- message_count: 30,
- snapshot_source: 'web',
- snapshot_library: '[email protected]',
- event_count: 15,
- retention_period_days: 30,
- },
- {
- uuid: expect.any(String),
- session_id: 'session123',
- team_id: 1,
- distinct_id: 'user1',
- batch_id: 'batch123',
- first_timestamp: '2025-01-01 10:00:03.000',
- last_timestamp: '2025-01-01 10:00:05.000',
- block_url: 's3://bucket/file1?range=bytes=250-449',
- first_url: 'https://example.com',
- urls: ['https://example.com', 'https://example.com/page3'],
- click_count: 7,
- keypress_count: 15,
- mouse_activity_count: 20,
- active_milliseconds: 2500,
- console_log_count: 4,
- console_warn_count: 1,
- console_error_count: 2,
- size: 2048,
- message_count: 70,
- snapshot_source: 'web',
- snapshot_library: '[email protected]',
- event_count: 35,
- retention_period_days: 30,
- },
- ])
+ expect(parsedEvents).toMatchObject([
+ {
+ uuid: expect.any(String),
+ session_id: 'session123',
+ team_id: 1,
+ distinct_id: 'user1',
+ batch_id: 'batch123',
+ first_timestamp: '2025-01-01 10:00:00.000',
+ last_timestamp: '2025-01-01 10:00:02.000',
+ block_url: 's3://bucket/file1?range=bytes=0-99',
+ first_url: 'https://example.com',
+ urls: ['https://example.com', 'https://example.com/page2'],
+ click_count: 5,
+ keypress_count: 10,
+ mouse_activity_count: 15,
+ active_milliseconds: 2000,
+ console_log_count: 3,
+ console_warn_count: 2,
+ console_error_count: 1,
+ size: 1024,
+ message_count: 50,
+ snapshot_source: 'mobile',
+ snapshot_library: 'posthog-ios',
+ snapshot_mode: snapshotMode,
+ event_count: 25,
+ retention_period_days: 30,
+ is_deleted: 0,
+ },
+ {
+ uuid: expect.any(String),
+ session_id: 'different456',
+ team_id: 2,
+ distinct_id: 'user2',
+ batch_id: 'batch123',
+ first_timestamp: '2025-01-01 10:00:01.500',
+ last_timestamp: '2025-01-01 10:00:03.500',
+ block_url: 's3://bucket/file1?range=bytes=100-249',
+ first_url: 'https://example.com/different',
+ urls: ['https://example.com/different'],
+ click_count: 2,
+ keypress_count: 5,
+ mouse_activity_count: 8,
+ active_milliseconds: 1500,
+ console_log_count: 1,
+ console_warn_count: 1,
+ console_error_count: 0,
+ size: 512,
+ message_count: 30,
+ snapshot_mode: null,
+ snapshot_source: 'web',
+ snapshot_library: '[email protected]',
+ event_count: 15,
+ retention_period_days: 30,
+ },
+ {
+ uuid: expect.any(String),
+ session_id: 'session123',
+ team_id: 1,
+ distinct_id: 'user1',
+ batch_id: 'batch123',
+ first_timestamp: '2025-01-01 10:00:03.000',
+ last_timestamp: '2025-01-01 10:00:05.000',
+ block_url: 's3://bucket/file1?range=bytes=250-449',
+ first_url: 'https://example.com',
+ urls: ['https://example.com', 'https://example.com/page3'],
+ click_count: 7,
+ keypress_count: 15,
+ mouse_activity_count: 20,
+ active_milliseconds: 2500,
+ console_log_count: 4,
+ console_warn_count: 1,
+ console_error_count: 2,
+ size: 2048,
+ message_count: 70,
+ snapshot_source: 'mobile',
+ snapshot_library: 'posthog-ios',
+ snapshot_mode: snapshotMode,
+ event_count: 35,
+ retention_period_days: 30,
+ },
+ ])
- // Verify UUIDs are unique
- const uuids = parsedEvents.map((event) => event.uuid)
- expect(new Set(uuids).size).toBe(3)
+ // Verify UUIDs are unique
+ const uuids = parsedEvents.map((event) => event.uuid)
+ expect(new Set(uuids).size).toBe(3)
- // Verify keys are set to correct session IDs
- expect(queuedMessages[0].key).toEqual('session123')
- expect(queuedMessages[1].key).toEqual('different456')
- expect(queuedMessages[2].key).toEqual('session123')
- })
+ // Verify keys are set to correct session IDs
+ expect(queuedMessages[0].key).toEqual('session123')
+ expect(queuedMessages[1].key).toEqual('different456')
+ expect(queuedMessages[2].key).toEqual('session123')
+ }
+ )
it('should handle empty blocks array', async () => {
await store.storeSessionBlocks([])
@@ -220,6 +229,7 @@ describe('SessionMetadataStore', () => {
batchId: 'batch123',
blockLength: 100,
eventCount: 10,
+ snapshotMode: null,
startDateTime: DateTime.fromISO('2025-01-01T10:00:00.000Z'),
endDateTime: DateTime.fromISO('2025-01-01T10:00:02.000Z'),
blockUrl: null,
@@ -253,6 +263,7 @@ describe('SessionMetadataStore', () => {
batchId: 'batch123',
blockLength: 100,
eventCount: 8,
+ snapshotMode: null,
startDateTime: DateTime.fromISO('2025-01-01T10:00:00.000Z'),
endDateTime: DateTime.fromISO('2025-01-01T10:00:02.000Z'),
blockUrl: null,
@@ -305,6 +316,7 @@ describe('SessionMetadataStore', () => {
batchId: 'batch1',
blockLength: 100,
eventCount: 12,
+ snapshotMode: null,
startDateTime: DateTime.fromISO('2025-01-01T10:00:00.000Z'),
endDateTime: DateTime.fromISO('2025-01-01T10:00:02.000Z'),
blockUrl: 's3://bucket/file1',
@@ -331,6 +343,7 @@ describe('SessionMetadataStore', () => {
batchId: 'batch2',
blockLength: 200,
eventCount: 18,
+ snapshotMode: null,
startDateTime: DateTime.fromISO('2025-01-01T10:00:03.000Z'),
endDateTime: DateTime.fromISO('2025-01-01T10:00:05.000Z'),
blockUrl: 's3://bucket/file2',
@@ -399,6 +412,7 @@ describe('SessionMetadataStore', () => {
const blocks = [
{
sessionId: 'deleted-session',
+ snapshotMode: null,
teamId: 1,
distinctId: 'user1',
batchId: 'batch1',
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.ts b/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.ts
index c0e5ec527102..59eabb2b9761 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/shared/metadata/session-metadata-store.ts
@@ -42,6 +42,7 @@ export class SessionMetadataStore extends KafkaMetadataSink<ReplayEventsOutput>
message_count: metadata.messageCount || 0,
snapshot_source: metadata.snapshotSource,
snapshot_library: metadata.snapshotLibrary,
+ snapshot_mode: metadata.snapshotMode,
event_count: metadata.eventCount || 0,
retention_period_days: metadata.retentionPeriodDays,
is_deleted: metadata.isDeleted ? 1 : 0,