#How to automatically start custom session replay?

6 messages · Page 1 of 1 (latest)

sleek igloo
#

I want to start session replay based on some query params like this:

 useEffect(() => {
    const campaignId = query.campaignid;
    console.log("campaign id", campaignId);

    return async () => {
      const replay = Sentry.getCurrentHub().getIntegration(Sentry.Replay);
      if (replay) {
        console.log("in replay");
        // Sentry.setTag("campaignid", campaignId);
        await replay.flush();
      }
    };
  }, []);

But this is not recording the session.

old marsh
sleek igloo
#

yes, I tried that, but session is already started somehow. I can confirm that bcz I'm getting the replay id. I'm using Nextjs
I have setup using this in sentry.client.ts

integrations: [
    new Sentry.Replay({
      // Additional Replay configuration goes in here, for example:
      maskAllText: false,
      blockAllMedia: false,
      networkDetailAllowUrls: [window.location.origin],
    }),
  ],
wicked sedge
#

@sleek igloo can you add debug: true in Sentry.init({debug: true}) and see if any errors come up in the logs?

sleek igloo
#

Yes, I tried, there were no errors. Do I need to add the replay integration in sentry.client.ts?
I guess that will start the session immediately. But I want to start the session based on the query params. Should I add the integration later on with an if check?

wicked sedge
#

@sleek igloo you can set sample rates to 0, call startBuffering() immediately, then whenever you want to capture a session, you can call flush() -- though I'm not sure why your current setup is not capturing