Skip to content

Commit c1d5492

Browse files
authored
docs(nextjs:session-replay) Clear sampling setup (#14425)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR - Adds an example configuration to Sampling section of Session Replay docs - Updates lazy loading docs to separate code blocks to be less confusing ### Before/After Screenshots | Before | After | |--------|-------| | <img width="2056" height="1247" alt="Screenshot 2025-07-22 at 2 40 58 PM" src="https://github.com/user-attachments/assets/6f8d3a33-6847-4ed7-aaa2-be546ab54e00" /> | <img width="2056" height="1247" alt="Screenshot 2025-07-22 at 2 41 26 PM" src="https://github.com/user-attachments/assets/09b75ed0-32af-493a-8c5c-4383ddc70d28" /> | | *No sample, no example of usage* | *Example with table for usage* | | <img width="774" height="425" alt="Screenshot 2025-07-22 at 2 42 07 PM" src="https://github.com/user-attachments/assets/4d31fe5b-010f-4b8f-81ba-10bb0f6f1d00" /> | <img width="760" height="518" alt="Screenshot 2025-07-22 at 2 41 59 PM" src="https://github.com/user-attachments/assets/c0469884-5947-4a0b-b698-fb3430432690" /> | | *Same code block makes it seem like it should be in the same file* | *Separate the blocks to make sure it's clear that they will be in 2 separate places* | ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 0d4d04f commit c1d5492

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

docs/platforms/javascript/common/session-replay/index.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,33 @@ Sampling allows you to control how much of your website's traffic will result in
157157
record up to a minute of events prior to the error and continue recording
158158
until the session ends.
159159

160+
```javascript {5-6} {filename:instrumentation-client.ts}
161+
Sentry.init({
162+
// ... other configuration
163+
164+
// Session Replay sampling rates
165+
replaysSessionSampleRate: 0.1, // Capture 10% of all sessions
166+
replaysOnErrorSampleRate: 1.0, // Capture 100% of error sessions
167+
168+
// For development/testing, you can set replaysSessionSampleRate to 1.0
169+
// to capture all sessions for complete visibility
170+
});
171+
```
172+
173+
### Recommended Production Sample Rates
174+
175+
Choose your `replaysSessionSampleRate` based on your traffic volume:
176+
177+
| Traffic Volume | Session Sample Rate | Error Sample Rate | Description |
178+
|---|---|---|---|
179+
| **High** (100k+ sessions/day) | `0.01` (1%) | `1.0` (100%) | Minimal session capture, all errors |
180+
| **Medium** (10k-100k sessions/day) | `0.1` (10%) | `1.0` (100%) | Balanced approach |
181+
| **Low** (under 10k sessions/day) | `0.25` (25%) | `1.0` (100%) | Higher session capture for better insights |
182+
183+
**Why keep `replaysOnErrorSampleRate` at 1.0?** Error sessions provide the most valuable debugging context, so capturing all of them is recommended regardless of traffic volume.
184+
185+
### How Sampling Works
186+
160187
Sampling begins as soon as a session starts. <PlatformIdentifier name="replays-session-sample-rate" /> is evaluated first. If it's sampled, the replay recording will begin. Otherwise, <PlatformIdentifier name="replays-on-error-sample-rate" /> is evaluated and if it's sampled, the integration will begin buffering the replay and will only upload it to Sentry if an error occurs. The remainder of the replay will behave similarly to a whole-session replay.
161188

162189
## Error Linking

platform-includes/configuration/integrations/lazy-loading-replay/javascript.nextjs.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ Sentry.init({
33
// Note, Replay is NOT instantiated below:
44
integrations: [],
55
});
6+
```
7+
8+
Then, somewhere in your application, for example in a `useEffect` hook, you can lazy-load the Replay integration:
69

7-
// Sometime later
10+
```javascript
811
import("@sentry/nextjs").then((lazyLoadedSentry) => {
912
Sentry.addIntegration(lazyLoadedSentry.replayIntegration());
1013
});
11-
```
14+
```

0 commit comments

Comments
 (0)