Skip to content

Replay manual start doesn't trigger recording #6605

Closed

Description

@earlAchromatic

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/vue

SDK Version

7.25

Framework Version

Vue 2.7.14

Link to Sentry event

No response

Steps to Reproduce

Initialize Sentry without Replay following the Replay docs:

Sentry.init({
    dsn: config.sentryDsn
    replaysOnErrorSampleRate: 1.0,
    integrations: [],
})

// initialize Replay outside of integrations

const replay = new Sentry.Replay()

replay.start() // no recording triggered on error

Expected Result

Expected recording to be triggered on error and show up in the UI. This doesn't happen.

Actual Result

No recording is sent to UI. This is because _setup is not called when Replay is initialized outside of the integrations array. _setup is responsible for initializing a ReplayContainer instance which is required to actually start a recording. The result is when Replay.start is called and Replay has been initialized outside of the Sentry config, no recording every takes place. I am able to manually start recording by doing this though:

const replay = new Sentry.Replay()

replay.setupOnce() // this method must be called to manually set up before starting.
replay.start()

I do not believe this the intended behavior. Or maybe this is intentional and the docs just need updated?

It looks like this could be fixed by calling setupOnce inside of Replay.start when it is called if a _setupComplete flag has not been previously set.

Activity

  1. Lms24 commented on Dec 22, 2022

    @Lms24
    Member

    Hi @earlAchromatic thanks for reporting this! This might have been an oversight while working on #6407 and subsequent refactorings. We'll look into this. For now, the workaround is to specify Replay in the integrations array of Sentry.init.

    Just out of curiosity: Why are you trying to initialize Replay manually?

  2. billyvg commented on Dec 22, 2022

    @billyvg
    Member

    FWIW we hit the same bug in Sentry SaaS, but we have a unique case since we are controlling SDK sampling from an external source (flagr), where feature flags are not available when calling Sentry.init.

  3. earlAchromatic commented on Dec 22, 2022

    @earlAchromatic
    Author

    Just out of curiosity: Why are you trying to initialize Replay manually?

    @Lms24 Our use case is dynamically initializing Replay based on a limited set of users that have opted in, in order to evaluate Replay. We have also talked about possibly using manual start/stop in order to scope inbound replays to specific features (think intersection observer or mouseenter events for instance) but that would be down the road. Thanks for giving it a look.

  4. mydea commented on Jan 13, 2023

    @mydea
    Member

    This can now be achieved with the new addIntegration API (added in 7.30):

    Sentry.init({
      // not added yet
      integrations: []
    });
    
    // sometime later:
    Sentry.getCurrentHub().getClient().addIntegration(new Sentry.Replay());

    This will properly register the integration & start the replay.

    Feel free to reopen this if that doesn't work as expected for you!

  5. brotherko commented on Feb 2, 2023

    @brotherko

    @mydea My idea is to sample 100% for certain users. But then only track the rest of the users on error. Given the sampling rate is set up in Sentry's top-level configuration, how to set this up?

  6. mydea commented on Feb 2, 2023

    @mydea
    Member

    You could achieve this with something like this:

    1. Do not add replay integration in Sentry.init()
    2. At the point in time where you do know that you want to setup replay (e.g. you know the user), do:
    const client = getCurrentHub().getClient()!;
    const options = client.getOptions();
    options.replaysSessionSampleRate = 0; // or 1
    options.replaysOnErrorSampleRate = 1; // or 0;
    
    client.addIntegration(new Replay()); // <-- this will trigger start

    Note that depending on when you call this, you may loose a portion of the replay (=stuff that happened before this).

    Note that we do not recommend to do this - ideally, you know at Sentry.init() time how you want to sample this session, as that's the only way to ensure we can capture the whole session correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions