You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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?
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.
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.
@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?
At the point in time where you do know that you want to setup replay (e.g. you know the user), do:
constclient=getCurrentHub().getClient()!;constoptions=client.getOptions();options.replaysSessionSampleRate=0;// or 1options.replaysOnErrorSampleRate=1;// or 0;client.addIntegration(newReplay());// <-- 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.
Activity
Lms24 commentedon Dec 22, 2022
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
Replayin theintegrationsarray ofSentry.init.Just out of curiosity: Why are you trying to initialize
Replaymanually?billyvg commentedon Dec 22, 2022
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.earlAchromatic commentedon Dec 22, 2022
@Lms24 Our use case is dynamically initializing
Replaybased 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.mydea commentedon Jan 13, 2023
This can now be achieved with the new
addIntegrationAPI (added in 7.30):This will properly register the integration & start the replay.
Feel free to reopen this if that doesn't work as expected for you!
brotherko commentedon Feb 2, 2023
@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?
mydea commentedon Feb 2, 2023
You could achieve this with something like this:
Sentry.init()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.