Skip to content

Commit dae0c99

Browse files
authored
docs(replay): Update README.md for lazy integrations (#7704)
1 parent 1ccfee8 commit dae0c99

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/replay/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ If you do not want to start Replay immediately (e.g. if you want to lazy-load it
6060
you can also use `addIntegration` to load it later:
6161

6262
```js
63+
import * as Sentry from "@sentry/react";
64+
import { BrowserClient } from "@sentry/browser";
65+
6366
Sentry.init({
6467
// Do not load it initially
6568
integrations: []
6669
});
6770

6871
// Sometime later
6972
const { Replay } = await import('@sentry/browser');
70-
getCurrentHub().getClient().addIntegration(new Replay());
73+
const client = Sentry.getCurrentHub().getClient<BrowserClient>();
74+
75+
// Client can be undefined
76+
client?.addIntegration(new Replay());
7177
```
7278
7379
### Identifying Users
@@ -76,6 +82,7 @@ If you have only followed the above instructions to setup session replays, you w
7682
7783
```javascript
7884
import * as Sentry from "@sentry/browser";
85+
7986
Sentry.setUser({ email: "[email protected]" });
8087
```
8188
@@ -84,17 +91,22 @@ Sentry.setUser({ email: "[email protected]" });
8491
Replay recording only starts when it is included in the `integrations` array when calling `Sentry.init` or calling `addIntegration` from the a Sentry client instance. To stop recording you can call the `stop()`.
8592
8693
```js
94+
import * as Sentry from "@sentry/react";
95+
import { BrowserClient } from "@sentry/browser";
96+
8797
const replay = new Replay();
98+
8899
Sentry.init({
89100
integrations: [replay]
90101
});
91102

92-
const client = getClient();
103+
const client = Sentry.getCurrentHub().getClient<BrowserClient>();
93104

94105
// Add replay integration, will start recoring
95-
client.addIntegration(replay);
106+
client?.addIntegration(replay);
96107

97-
replay.stop(); // Stop recording
108+
// Stop recording
109+
replay.stop();
98110
```
99111
100112
## Loading Replay as a CDN Bundle

0 commit comments

Comments
 (0)