Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: session idle timestamp correction #1428

Merged
merged 2 commits into from
Sep 23, 2024
Merged
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
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
Loading