|
1 | | -On your client-side NextJS app, add: |
| 1 | +Session Replay is configured in your **client-side** initialization file only. |
2 | 2 |
|
3 | | -```javascript {8,12,14-20} {filename:instrumentation-client.ts} |
| 3 | +<SplitLayout> |
| 4 | + |
| 5 | +<SplitSection> |
| 6 | +<SplitSectionText> |
| 7 | + |
| 8 | +#### Add Replay Integration |
| 9 | + |
| 10 | +Add `replayIntegration()` to your client initialization and configure the sample rates. |
| 11 | + |
| 12 | +**Testing tip:** Set `replaysSessionSampleRate: 1.0` during development to capture all sessions. |
| 13 | + |
| 14 | +</SplitSectionText> |
| 15 | +<SplitSectionCode> |
| 16 | + |
| 17 | +```typescript {filename:instrumentation-client.ts} |
4 | 18 | import * as Sentry from "@sentry/nextjs"; |
5 | 19 |
|
6 | 20 | Sentry.init({ |
7 | 21 | dsn: "___PUBLIC_DSN___", |
8 | 22 |
|
9 | | - // This sets the sample rate to be 10%. You may want this to be 100% while |
10 | | - // in development and sample at a lower rate in production |
| 23 | + // Capture 10% of all sessions |
11 | 24 | replaysSessionSampleRate: 0.1, |
12 | 25 |
|
13 | | - // If the entire session is not sampled, use the below sample rate to sample |
14 | | - // sessions when an error occurs. |
| 26 | + // Capture 100% of sessions with errors |
15 | 27 | replaysOnErrorSampleRate: 1.0, |
16 | 28 |
|
17 | | - integrations: [ |
18 | | - Sentry.replayIntegration({ |
19 | | - // Additional SDK configuration goes in here, for example: |
20 | | - maskAllText: true, |
21 | | - blockAllMedia: true, |
22 | | - }), |
23 | | - ], |
| 29 | + integrations: [Sentry.replayIntegration()], |
24 | 30 | }); |
25 | 31 | ``` |
26 | 32 |
|
27 | | -### Verify |
| 33 | +</SplitSectionCode> |
| 34 | +</SplitSection> |
| 35 | + |
| 36 | +<SplitSection> |
| 37 | +<SplitSectionText> |
| 38 | + |
| 39 | +#### Privacy Options |
28 | 40 |
|
29 | | -While you're testing, we recommend that you set `replaysSessionSampleRate` to `1.0`. This ensures that every user session will be sent to Sentry. |
| 41 | +By default, Replay masks all text and blocks media. Customize privacy settings based on your needs. |
30 | 42 |
|
31 | | -Once testing is complete, **we recommend lowering this value in production**. We still recommend keeping `replaysOnErrorSampleRate` set to `1.0`, so that, whenever possible, every error has an associated replay with additional debugging context. |
| 43 | +See <PlatformLink to="/session-replay/privacy/">Session Replay Privacy</PlatformLink> for all options. |
32 | 44 |
|
33 | | -### PII & Privacy Considerations |
| 45 | +</SplitSectionText> |
| 46 | +<SplitSectionCode> |
34 | 47 |
|
35 | | -Personally identifiable information (PII), and privacy are important considerations when enabling Session Replay. There are multiple ways in which Sentry helps you avoid collecting PII, including: |
| 48 | +```typescript {filename:instrumentation-client.ts} |
| 49 | +Sentry.replayIntegration({ |
| 50 | + // Text masking (default: true) |
| 51 | + maskAllText: true, |
| 52 | + |
| 53 | + // Block images/videos (default: true) |
| 54 | + blockAllMedia: true, |
| 55 | + |
| 56 | + // Mask specific inputs |
| 57 | + maskAllInputs: true, |
| 58 | +}), |
| 59 | +``` |
36 | 60 |
|
37 | | -- [Masking](/platforms/javascript/session-replay/privacy/#masking), which replaces the text content with something else. (The default behavior being to replace each character with a \*.) |
38 | | -- Making [Network request, response bodies, and headers](/platforms/javascript/session-replay/privacy/#network-request-and-response-bodies-and-headers) an opt-in feature, because the best way to avoid getting PII into Sentry is by not adding URLs of endpoints that may contain PII. |
| 61 | +</SplitSectionCode> |
| 62 | +</SplitSection> |
39 | 63 |
|
40 | | -While we have certain privacy considerations in place, Sentry's Session Replays allow you to set up the [privacy configurations](/platforms/javascript/session-replay/privacy/#privacy-configuration) that work best for your use case. For example, if you're working on a static website that's free of PII or other types of private data, you can opt out of the default text masking and image blocking settings. |
41 | | -To learn more about session replay privacy, [read our docs.](/platforms/javascript/session-replay/privacy/) |
| 64 | +<SplitSection> |
| 65 | +<SplitSectionText> |
42 | 66 |
|
43 | | -### Lazy-loading Replay |
| 67 | +#### Lazy-Loading Replay |
44 | 68 |
|
45 | | -Once you've added the integration, Replay will start automatically. If you don't want to start it immediately (lazy-load it), you can use `addIntegration`: |
| 69 | +Load Replay only when needed instead of at startup. Useful for reducing initial bundle size. |
| 70 | + |
| 71 | +</SplitSectionText> |
| 72 | +<SplitSectionCode> |
| 73 | + |
| 74 | +```typescript {filename:instrumentation-client.ts} |
| 75 | +// Don't add replayIntegration to init |
| 76 | +Sentry.init({ |
| 77 | + integrations: [], |
| 78 | +}); |
| 79 | + |
| 80 | +// Later, when you want to start recording: |
| 81 | +import("@sentry/nextjs").then((lazyLoadedSentry) => { |
| 82 | + Sentry.addIntegration(lazyLoadedSentry.replayIntegration()); |
| 83 | +}); |
| 84 | +``` |
| 85 | + |
| 86 | +</SplitSectionCode> |
| 87 | +</SplitSection> |
| 88 | + |
| 89 | +</SplitLayout> |
| 90 | + |
| 91 | +### Verify |
46 | 92 |
|
47 | | -<PlatformContent includePath="configuration/integrations/lazy-loading-replay" /> |
| 93 | +Open your app, interact with it, then check [**Replays**](https://sentry.io/orgredirect/organizations/:orgslug/replays/) in Sentry to see your session. |
0 commit comments