Skip to content

Commit

Permalink
fix: force TS numbers to be ints (#17348)
Browse files Browse the repository at this point in the history
* fix: force TS numbers to be ints

* fix

* fix

* fix
  • Loading branch information
pauldambra authored Sep 12, 2023
1 parent 9925638 commit da40d4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
26 changes: 14 additions & 12 deletions plugin-server/src/worker/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export interface SummarizedSessionRecordingEvent {
team_id: number
distinct_id: string
session_id: string
first_url: string | undefined
first_url: string | null
click_count: number
keypress_count: number
mouse_activity_count: number
Expand Down Expand Up @@ -311,7 +311,7 @@ export const createSessionReplayEvent = (
let consoleLogCount = 0
let consoleWarnCount = 0
let consoleErrorCount = 0
let url: string | undefined = undefined
let url: string | null = null
events.forEach((event) => {
if (event.type === 3) {
mouseActivity += 1
Expand All @@ -322,7 +322,7 @@ export const createSessionReplayEvent = (
keypressCount += 1
}
}
if (!!event.data?.href?.trim().length && url === undefined) {
if (url === null && !!event.data?.href?.trim().length) {
url = event.data.href
}
if (event.type === 6 && event.data?.plugin === 'rrweb/console@1') {
Expand All @@ -339,22 +339,24 @@ export const createSessionReplayEvent = (

const activeTime = activeMilliseconds(events)

// NB forces types to be correct e.g. by truncating or rounding
// to ensure we don't send floats when we should send an integer
const data: SummarizedSessionRecordingEvent = {
uuid,
team_id: team_id,
distinct_id: distinct_id,
distinct_id: String(distinct_id),
session_id: session_id,
first_timestamp: timestamps[0],
last_timestamp: timestamps[timestamps.length - 1],
click_count: clickCount,
keypress_count: keypressCount,
mouse_activity_count: mouseActivity,
click_count: Math.trunc(clickCount),
keypress_count: Math.trunc(keypressCount),
mouse_activity_count: Math.trunc(mouseActivity),
first_url: url,
active_milliseconds: activeTime,
console_log_count: consoleLogCount,
console_warn_count: consoleWarnCount,
console_error_count: consoleErrorCount,
size: Buffer.byteLength(JSON.stringify(events), 'utf8'),
active_milliseconds: Math.round(activeTime),
console_log_count: Math.trunc(consoleLogCount),
console_warn_count: Math.trunc(consoleWarnCount),
console_error_count: Math.trunc(consoleErrorCount),
size: Math.trunc(Buffer.byteLength(JSON.stringify(events), 'utf8')),
}

return data
Expand Down
8 changes: 4 additions & 4 deletions plugin-server/tests/main/process-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ const sessionReplayEventTestCases: {
click_count: 1,
keypress_count: 0,
mouse_activity_count: 1,
first_url: undefined,
first_url: null,
first_timestamp: '2023-04-25 18:58:13.469',
last_timestamp: '2023-04-25 18:58:13.469',
active_milliseconds: 1, // one event, but it's active, so active time is 1ms not 0
Expand All @@ -1260,7 +1260,7 @@ const sessionReplayEventTestCases: {
click_count: 0,
keypress_count: 1,
mouse_activity_count: 1,
first_url: undefined,
first_url: null,
first_timestamp: '2023-04-25 18:58:13.469',
last_timestamp: '2023-04-25 18:58:13.469',
active_milliseconds: 1, // one event, but it's active, so active time is 1ms not 0
Expand Down Expand Up @@ -1316,7 +1316,7 @@ const sessionReplayEventTestCases: {
click_count: 0,
keypress_count: 1,
mouse_activity_count: 1,
first_url: undefined,
first_url: null,
first_timestamp: '2023-04-25 18:58:13.469',
last_timestamp: '2023-04-25 18:58:13.469',
active_milliseconds: 1, // one event, but it's active, so active time is 1ms not 0
Expand Down Expand Up @@ -1381,7 +1381,7 @@ const sessionReplayEventTestCases: {
click_count: 6,
keypress_count: 0,
mouse_activity_count: 6,
first_url: undefined,
first_url: null,
first_timestamp: '2023-04-25 18:58:13.000',
last_timestamp: '2023-04-25 18:58:19.000',
active_milliseconds: 6000, // can sum up the activity across windows
Expand Down

0 comments on commit da40d4c

Please sign in to comment.