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: flushing the buffer for debug signal while idle extends session activity #1396

Merged

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented Sep 2, 2024

In stepping through what we do around idleness in the recorder

  • we only check and extend session if it’s an interactive event
  • i.e. if the user is not idle
  • Reading the code of checkAndGetSessionAndWindowId you must check and extend session in order to check idle timeout

  • So you can’t have an idle timeout in recording unless you return from idle 🤯
  • While idle we only allow custom events

they go into the in-memory buffer

when that happens…
  • the buffer is flushed if the session id has changed or if the buffer holds > 0.9MBish

and if not we set a two second timer which will flush the buffer


  • when flushing the buffer
so long as the buffer is not empty we capture a snapshot with the buffer contents

  • that calls capture on the posthog instance


  • which among other things makes a non-readonly check of the session id and window id
  • which might cause the session id to change generally
  • and for the message being captured
overwriting the data being sent with the new session and window id
  • and checking the session/window id extends the activity timer
  • so if a session has frequent enough custom events while idle it would never idle timeout

This PR ensures we don't flush the buffer when idle but still allows buffering (allowed) snapshot data while idle

TESTING

validated i can still record locally, and that sessions go idle and return from idle

Screenshot 2024-09-02 at 09 53 32

TODO

session rotating on idle but after resuming from idle

Screenshot 2024-09-02 at 10 57 06

Copy link

vercel bot commented Sep 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Sep 2, 2024 11:51am

@pauldambra pauldambra requested a review from a team September 2, 2024 08:01
Copy link

github-actions bot commented Sep 2, 2024

Size Change: +268 B (+0.02%)

Total Size: 1.17 MB

Filename Size Change
dist/array.full.js 335 kB +67 B (+0.02%)
dist/array.js 156 kB +67 B (+0.04%)
dist/main.js 157 kB +67 B (+0.04%)
dist/module.js 156 kB +67 B (+0.04%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 10.4 kB
dist/recorder-v2.js 110 kB
dist/recorder.js 110 kB
dist/surveys-preview.js 59.8 kB
dist/surveys.js 66 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

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