Skip to content

Commit

Permalink
fix: session idle timestamp correction (#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Sep 23, 2024
1 parent 979f235 commit 44bf2fd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/extensions/replay/sessionrecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ interface QueuedRRWebEvent {
enqueuedAt: number
}

interface SessionIdlePayload {
eventTimestamp: number
lastActivityTimestamp: number
threshold: number
bufferLength: number
bufferSize: number
}

const newQueuedEvent = (rrwebMethod: () => void): QueuedRRWebEvent => ({
rrwebMethod,
enqueuedAt: Date.now(),
Expand Down Expand Up @@ -799,6 +807,18 @@ export class SessionRecording {
return
}

if (event.type === EventType.Custom && event.data.tag === 'sessionIdle') {
// session idle events have a timestamp when rrweb sees them
// which can artificially lengthen a session
// we know when we detected it based on the payload and can correct the timestamp
const payload = event.data.payload as SessionIdlePayload
if (payload) {
const lastActivity = payload.lastActivityTimestamp
const threshold = payload.threshold
event.timestamp = lastActivity + threshold
}
}

const properties = {
$snapshot_bytes: size,
$snapshot_data: event,
Expand Down

0 comments on commit 44bf2fd

Please sign in to comment.