[Session Replay]Why "Multiple Sentry Session Replay instances are not supported"? #8414
-
Hi there. I'm trying to use Sesson Replay in a React project. I already use Sentry in my project, so I init Sentry in ■index.tsx I want to replay only certain pages, so I wrote the following code. ■Sample.tsx
The version of the I will let you know if there is any other information needed to solve the problem. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @NiiyaDaiki - there are two issues here. First, you don't need to call I would recommend doing something like this: let hasReplayInit = false;
function initReplay() {
if (hasReplayInit) {
return;
}
const client = Sentry.getCurrentHub().getClient()
const replay = new Sentry.Replay()
// only reason client doesn't exist is that `Sentry.init` was not called.
if (client && client.addIntegration) {
client.addIntegration(replay)
hasReplayInit = true;
}
}
const SamplePage = () => {
useEffect(() => {
initReplay();
}, []);
return <>sample</>
} |
Beta Was this translation helpful? Give feedback.
-
I just encountered same error while trying to lazy-load sentry in a react vite project. Here's how I handled it.
|
Beta Was this translation helpful? Give feedback.
Hey @NiiyaDaiki - there are two issues here. First, you don't need to call
replay.start()
, this is already done by callingclient.addIntegration(replay)
. Second, By putting the replay init in a component, you run the risk of re-running replay integration creationI would recommend doing something like this: