PostHog / posthog

๐Ÿฆ” PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
21.27k stars 1.27k forks source link

Start session recording on trigger #25340

Open richard-better opened 4 days ago

richard-better commented 4 days ago

Feature request

We'd like to trigger session recordings when something happens.

This could be:

Two reasons we want this:

  1. Allow users to only record when something they find interesting happens
  2. As a form of cost control.

These are already possible, but you need to to write custom code to stop/start the recording: ideally this should be configurable in the Ingestion controls as well.

richard-better commented 4 days ago

Questions to @pauldambra:

  1. Do we need a way to stop the recording? A user might trigger a start condition, but then the recording could continue for hours. Is this okay? (I think it's fine to not do that for now, and just keep recording.)
  2. How much buffer should we keep in memory before the trigger?
    1. Are we okay with losing context for apps that are non-SPA?
  3. We should respect ongoing sessions, and continue recording, even if the trigger condition is not met, right?
pauldambra commented 4 days ago

Do we need a way to stop the recording? A user might trigger a start condition, but then the recording could continue for hours. Is this okay? (I think it's fine to not do that for now, and just keep recording.)

Yep, I think this is the sensible default. We're not saying "only record on URL blah" but rather "start recording when trigger X fires"

Arguably we'd need to follow up with a denylist. So someone could say start on URL A, B, or C, but stop on URL D. So that in a journey 1, 2, A, D, B, C the recording shows A, B, C. But it's probably best as a user initiated follow-up to avoid adding features that nobody uses ๐Ÿ™ˆ

So, currently we start

and now we'd add one or more new triggers

but the default behaviour remains - once started the recording continues until idle timeout or someone calls stop in their code

(open to challenge ofc but that's my 2ยข :))

pauldambra commented 4 days ago

How much buffer should we keep in memory before the trigger?

By default we take a snapshot every 5 minutes So, we could say we dump the buffer on any full snapshot and so we keep 5 minutes

But that feels like a lot to store in memory, and for a 2 minutes session would mean that when we trigger based on condition it's like there was no trigger anyway

What's interesting is this is maybe different for different triggers... I can imagine "only start on URL A" means "don't show me anything before that". But "only start on $exception event" means "and a little bit before so i have some context for the error"

My gut feeling is we should full snapshot every 60 seconds while buffering and drop anything before each snapshot so we always have a little bit of lead up, and then add a custom event to the recording at the point of the trigger. That way we could ignore data before the trigger, and can at least make it clear to the user in the UI when the trigger occurred.

Are we okay with losing context for apps that are non-SPA?

for sampling iirc we write a flag to persistence (if enabled) so that the recording continues on refresh. so we could take the same approach here... if you already started then we'd continue

with minimum duration, we already drop the buffered data on refresh and most folk don't notice so my guess is majority of sites are doing client side navigations and we can ignore (for now) the case where you have some buffered data, navigate to the trigger URL or and then see the triggering event, and start recording having lost the in-memory buffer

we should probably at some point add a persistent buffer but ๐Ÿ™ˆ

pauldambra commented 4 days ago

We should respect ongoing sessions, and continue recording, even if the trigger condition is not met, right?

I think yes... but the drawback is with a 24 hour max session setting if you have long sessions you won't see the trigger start to take effect. I think we can leave this to be whichever is easiest.

My gut would be:

I feel ok with standing that since folk i think will mostly care about new sessions from the point they set the trigger