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: safer custom event on return from idle #913

Merged
merged 4 commits into from
Nov 28, 2023

Conversation

pauldambra
Copy link
Member

https://posthog.sentry.io/issues/4662102372/?project=1899813&query=is%3Aunresolved+please+add+custom+event+after+start+recording+PostHog-Recording-URL%3A%22https%3A%2F%2Fapp.posthog.com%2Freplay%2F018c1241-c72e-7c77-855b-e0bd29823f63%3Ft%3D756%22&referrer=issue-stream&statsPeriod=24h&stream_index=0

We see an error where setting a custom event on the session on return from idle is failing because the rrweb recording isn't ready to accept events.

Immediately after that we try to take a full snapshot and swallow any errors

But the full snapshot is relatively important.

Let's make those activities one activity and add a simple retry.

@pauldambra pauldambra added the bump patch Bump patch version when this PR gets merged label Nov 27, 2023
@pauldambra pauldambra requested a review from a team November 27, 2023 22:27
Copy link

github-actions bot commented Nov 27, 2023

Size Change: +824 B (0%)

Total Size: 744 kB

Filename Size Change
dist/array.full.js 176 kB +206 B (0%)
dist/array.js 117 kB +206 B (0%)
dist/es.js 117 kB +206 B (0%)
dist/module.js 118 kB +206 B (0%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 12 kB
dist/recorder-v2.js 104 kB
dist/recorder.js 58.4 kB
dist/surveys.js 41.5 kB

compressed-size-action

Comment on lines 443 to 460
let tries = 0
const retryingFn = () => {
tries++
if (tries > 3) {
logger.warn('Could not take full snapshot after 150 milliseconds. Giving up.')
return
}

try {
if (withCustomEvent) {
this.rrwebRecord?.addCustomEvent(withCustomEvent.tag, withCustomEvent.payload)
}
this.rrwebRecord?.takeFullSnapshot()
} catch (e) {
setTimeout(retryingFn, 50)
}
}
retryingFn()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this change... If the recorder hasn't started - that's okay right? We wouldn't take a full snapshot, as the starting of the recorder will take the snapshot.

It feels unnecessary and the real fix is in having the customEvent come after the _captureStarted check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's where I was heading, but we already had take full snapshot wrapped in a check to swallow failing to take one. So, the code was written to drop the request for a full snapshot. Which feels wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this is on return from idle so everything should already be running

but, let's swallow the error the same way and get the error out of sentry. it's only a debug signal

@pauldambra pauldambra merged commit 6990c1e into master Nov 28, 2023
13 checks passed
@pauldambra pauldambra deleted the fix/safer-snapshot-on-return-from-idle branch November 28, 2023 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants