Skip to content
64 changes: 40 additions & 24 deletions src/platforms/javascript/common/session-replay/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ title: Configuration
sidebar_order: 4100
notSupported:
- javascript.cordova
- javascript.electron
- javascript.wasm
description: 'Learn about the general Session Replay configuration fields.'
---
Expand All @@ -19,42 +18,59 @@ The following options can be configured on the root level of your browser-based
| replaysSessionSampleRate | number | `0` | The sample rate for replays that begin recording immediately and last the entirety of the user's session. `1.0` collects all replays, and `0` collects none. |
| replaysOnErrorSampleRate | number | `0` | The sample rate for replays that are recorded when an error happens. This type of replay will record up to a minute of events prior to the error and continue recording until the session ends. `1.0` captures all sessions with an error, and `0` captures none. |

The following options can be configured as options to the integration, in `new Replay({})`:
The following can be configured as integration options in `new Replay({})`:

| Key | Type | Default | Description |
| ------------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| stickySession | boolean | `true` | Keep track of the user across page loads. Note, a single user using multiple tabs will result in multiple sessions. Closing a tab will result in the session being closed as well. |
| Key | Type | Default | Description |
| ---------------------- | -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| stickySession | boolean | `true` | Keep track of users across page loads. Note, because closing a tab ends the session, a single user using multiple tabs will be recorded as multiple sessions. |
| networkDetailAllowUrls | (string \| RegExp)[] | `[]` | Capture request and response details for XHR and fetch requests that match the given URLs. |
| networkCaptureBodies | boolean | `true` | Decide whether to capture request and response bodies for URLs defined in `networkDetailAllowUrls`. |
| networkRequestHeaders | string[] | `[]` | Capture request headers for URLs defined in `networkDetailAllowUrls`. See [Network Details](#network-details) to learn more. |
| networkResponseHeaders | string[] | `[]` | Capture response headers for URLs defined in `networkDetailAllowUrls`. See [Network Details](#network-details) to learn more. |

## Identifying Users
### Sampling

To learn more about how session sampling works, check out our <PlatformLink to="/session-replay/understanding-sessions/#default-session-initialization">Default Session Initialization</PlatformLink> docs.

### Network Details

By default, Replay will capture basic information about all outgoing fetch and XHR requests in your application. This includes the URL, request and response body size, method, and status code. The intention is to limit the chance of collecting private data.

You can use the Sentry SDK to set the user of a session. To associate a user identity to a session replay, refer to the <PlatformLink to="/enriching-events/identify-user">Identifying User Docs</PlatformLink>.
To capture additional information such as request and response headers or bodies, you'll need to opt-in via `networkDetailAllowUrls`. This will make it possible for you to elect to only add URLs that are safe for capturing bodies and avoid any endpoints that may contain Personal Identifiable Information, (PII).

Any URL matching the given pattern(s) will then be captured with additional details:

```javascript
Sentry.setUser({ email: "[email protected]" });
new Replay({
networkDetailAllowUrls: ['https://my-website.com/api'],
});
```

## Start and Stop Recording
If you give us a string, we'll match any URL that contains that string. You can use a regex to handle exact or more complex matches.

Replay recording starts if it's included in the `integrations` array when calling `Sentry.init` or, when `addIntegration` is called from a Sentry client instance. To stop recording, call `stop()`:
Requests to a URL matched by the configured patterns will be enhanced with the request and response body, as well as the following default headers:

```javascript
const replay = new Sentry.Replay();
* `content-type`
* `content-length`
* `accept`

// Load replay when you configure Sentry SDK
Sentry.init({
integrations: [replay],
});
If you want to capture additional headers, you'll have to configure them with the options `networkRequestHeaders` and `networkResponseHeaders`.

<Note>
Captured bodies will be truncated to 150k characters max. Content in
bodies will be PII-sanitized server-side, based on object keys and values.
</Note>

### Sensitive Data in Request and Response Bodies

// Or if you want to defer loading Replay
getCurrentHub()
.getClient()
.addIntegration(replay);
Sentry attempts to scrub certain types of sensitive data from request and response bodies, if you accidentally opt-in to a URL that includes this type of data. This mechanism happens on our ingestion service, before data hits our disks. This is a best effort approach which pattern-matches the content with things like credit card information, social security numbers, and [passwords](https://github.com/search?q=repo%3Agetsentry%2Frelay%20PASSWORD_KEY_REGEX&type=code). The best way to avoid getting PII into Sentry is by not adding URLs of endpoints that may contain PII.

// sometime later
await replay.flush(); // wait for any pending recording data to be sent
replay.stop();
## Identifying Users

You can use the Sentry SDK to link a user to a session. Read more about it in our <PlatformLink to="/enriching-events/identify-user">docs</PlatformLink>.

replay.start();
```javascript
Sentry.setUser({email: '[email protected]'});
```

## Privacy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: Understanding Sessions
sidebar_order: 4300
notSupported:
- javascript.cordova
- javascript.wasm
description: 'Learn about customizing sessions with the Session Replay SDK.'
---

Comment thread
mydea marked this conversation as resolved.
Resolved
In most cases, setting the Replay sample rates will be all you need to do to begin capturing recording data you care about.
For more complex cases, it's helpful to understand how sessions work and how to manually control them.

## Default Session Initialization

By default, Replay will immediately start a session in either `session` or `buffer` mode, depending on your `replaysSessionSampleRate` and `replaysOnErrorSampleRate`.

When Replay is initialized, we check the `replaysSessionSampleRate`. If it's sampled, we'll start recording and sending Replay data immediately.

If `replaysOnErrorSampleRate > 0`, we'll start recording in buffering mode and keep checking `replaysOnErrorSampleRate` whenever an error occurs. Once we see that it's sampled, we'll upload the Replay to Sentry and continue recording normally.

If both `replaysSessionSampleRate` and `replaysOnErrorSampleRate` are `0`, the recording won't start, but you'll be able to <PlatformLink to="/session-replay/understanding-sessions/#manually-starting-recording">record manually</PlatformLink>.

## Session Mode

In `session` mode, Replay will continuously record and send data to Sentry. After 15 minutes of user inactivity, or a maximum duration of 60 minutes, the session will end and a new session will be initialized based on the rules from the section above.

## Buffer Mode

In `buffer` mode, Replay will continuously record data, but won't send any of it. It will instead keep up to the last 60 seconds in memory. When an error occurs, `replaysOnErrorSampleRate` will be checked and if it's sampled, the replay will be uploaded to Sentry and continue recording normally. After 15 minutes of user inactivity, or a maximum duration of 60 minutes, the session will end and the replay will stop.

## Manually Starting Replay

You can manually start a Replay session with:

```javascript
// This initializes Replay without starting any session
const replay = new Sentry.Replay({
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 0,
});

// This starts in `session` mode, regardless of sample rates
replay.start();

Comment thread
mydea marked this conversation as resolved.
Resolved
// OR

// This starts in `buffer` mode, regardless of sample rates
replay.startBuffering();
```

This can be used either if both `replaysSessionSampleRate` and `replaysOnErrorSampleRate` are `0` and thus no session has been started automatically, or if you previously stopped a session and want to start a new one (see below). `start` and `startBuffering` will throw an error if a session is currently running.

## Manually Stopping Replay

You can always stop a running session with:

```javascript
await replay.stop();
```

This will flush any pending recording data, stop the replay, and end the session.

## Manually Flushing Recording Data

You can flush any pending recording data with:

```javascript
await replay.flush();
```

In `session` mode, this will upload any pending recording data to Sentry. In `buffer` mode, this will upload any pending recording data to Sentry and then continue recording, the same as when an error is sampled with `replaysOnErrorSampleRate`.