7.116.0 • Published 2 months ago

@sentry/replay v7.116.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Sentry Session Replay

npm version npm dm npm dt

Pre-requisites

@sentry/replay requires Node 12+, and browsers newer than IE11.

Installation

Replay can be imported from @sentry/browser, or a respective SDK package like @sentry/react or @sentry/vue. You don't need to install anything in order to use Session Replay. The minimum version that includes Replay is 7.27.0.

For details on using Replay when using Sentry via the CDN bundles, see CDN bundle.

Setup

To set up the integration, add the following to your Sentry initialization. Several options are supported and passable via the integration constructor. See the configuration section below for more details.

import * as Sentry from '@sentry/browser';
// or e.g. import * as Sentry from '@sentry/react';

Sentry.init({
  dsn: '__DSN__',

  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,

  // If the entire session is not sampled, use the below sample rate to sample
  // sessions when an error occurs.
  replaysOnErrorSampleRate: 1.0,

  integrations: [
    new Sentry.Replay({
      // Additional SDK configuration goes in here, for example:
      maskAllText: true,
      blockAllMedia: true
      // See below for all available options
    })
  ],
  // ...
});

Lazy loading Replay

Replay will start automatically when you add the integration. If you do not want to start Replay immediately (e.g. if you want to lazy-load it), you can also use addIntegration to load it later:

import * as Sentry from "@sentry/react";
import { BrowserClient } from "@sentry/browser";

Sentry.init({
  // Do not load it initially
  integrations: []
});

// Sometime later
const { Replay } = await import('@sentry/browser');
const client = Sentry.getCurrentHub().getClient<BrowserClient>();

// Client can be undefined
client?.addIntegration(new Replay());

Identifying Users

If you have only followed the above instructions to setup session replays, you will only see IP addresses in Sentry's UI. In order to associate a user identity to a session replay, use setUser.

import * as Sentry from "@sentry/browser";

Sentry.setUser({ email: "jane.doe@example.com" });

Stopping & starting Replays manually

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 stop().

import * as Sentry from "@sentry/react";
import { BrowserClient } from "@sentry/browser";

const replay = new Replay();

Sentry.init({
  integrations: [replay]
});

const client = Sentry.getCurrentHub().getClient<BrowserClient>();

// Add replay integration, will start recoring
client?.addIntegration(replay);

// Stop recording
replay.stop();

When both replaysSessionSampleRate and replaysOnErrorSampleRate are 0, recording will not start. In this case, you can manually start recording:

replay.start(); // Will start a session in "session" mode, regardless of sample rates
replay.startBuffering(); // Will start a session in "buffer" mode, regardless of sample rates

Loading Replay as a CDN Bundle

As an alternative to the NPM package, you can use Replay as a CDN bundle. Please refer to the Session Replay installation guide for CDN bundle instructions.

<script
  src="https://browser.sentry-cdn.com/7.41.0/bundle.min.js"
  crossorigin="anonymous"
></script>
<script
  src="https://browser.sentry-cdn.com/7.41.0/replay.min.js"
  crossorigin="anonymous"
></script>

Sessions

A session starts when the Session Replay SDK is first loaded and initialized. The session will continue until 5 minutes passes without any user interactions^1 with the application OR until a maximum of 30 minutes have elapsed. Closing the browser tab will end the session immediately according to the rules for SessionStorage.

^1: An 'interaction' refers to either a mouse click or a browser navigation event.

Accessing the Replay Session ID

You can get the ID of the currently running session via replay.getReplayId(). This will return undefined if no session is ongoing.

Replay Captures Only on Errors

Alternatively, rather than recording an entire session, you can capture a replay only when an error occurs. In this case, the integration will buffer up to one minute worth of events prior to the error being thrown. It will continue to record the session following the rules above regarding session life and activity. Read the sampling section for configuration options.

Sampling

Sampling allows you to control how much of your website's traffic will result in a Session Replay. There are two sample rates you can adjust to get the replays more relevant to your interests:

  • replaysSessionSampleRate - The sample rate for replays that begin recording immediately and last the entirety of the user's session.
  • replaysOnErrorSampleRate - 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.

When Replay is initialized, we check the replaysSessionSampleRate. If it is sampled, then we start recording & sending Replay data immediately. Else, if replaysOnErrorSampleRate > 0, we'll start recording in buffering mode. In this mode, whenever an error occurs we'll check replaysOnErrorSampleRate. If it is sampled, when we'll upload the Replay to Sentry and continue recording normally.

Configuration

SDK Configuration

The following options can be configured on the root level of your browser-based Sentry SDK, in init({}):

keytypedefaultdescription
replaysSessionSampleRatenumber0The sample rate for replays that begin recording immediately and last the entirety of the user's session. 1.0 will collect all replays, 0 will collect no replays.
replaysOnErrorSampleRatenumber0The 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 capturing all sessions with an error, and 0 capturing none.

General Integration Configuration

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

keytypedefaultdescription
stickySessionbooleantrueKeep 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.

Privacy Configuration

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

keytypedefaultdescription
maskAllTextbooleantrueMask all text content. Will pass text content through maskFn before sending to server.
maskAllInputsbooleantrueMask values of <input> elements. Passes input values through maskInputFn before sending to server.
blockAllMediabooleantrueBlock all media elements (img, svg, video, object, picture, embed, map, audio)
maskFn(text: string) => string(text) => '*'.repeat(text.length)Function to customize how text content is masked before sending to server. By default, masks text with *.
blockArray.sentry-block, [data-sentry-block]Redact any elements that match the DOM selectors. See privacy section for an example.
unblockArray.sentry-unblock, [data-sentry-unblock]Do not redact any elements that match the DOM selectors. Useful when using blockAllMedia. See privacy section for an example.
maskArray.sentry-mask, [data-sentry-mask]Mask all elements that match the given DOM selectors. See privacy section for an example.
unmaskArray.sentry-unmask, [data-sentry-unmask]Unmask all elements that match the given DOM selectors. Useful when using maskAllText. See privacy section for an example.
ignoreArray.sentry-ignore, [data-sentry-ignore]Ignores all events on the matching input fields. See privacy section for an example.

Deprecated options

In order to streamline our privacy options, the following have been deprecated in favor for the respective options above.

deprecated keyreplaced bydescription
maskInputOptionsmaskUse CSS selectors in mask in order to mask all inputs of a certain type. For example, input[type="address"]
blockSelectorblockThe selector(s) can be moved directly in the block array.
blockClassblockConvert the class name to a CSS selector and add to block array. For example, first-name becomes .first-name. Regexes can be moved as-is.
maskClassmaskConvert the class name to a CSS selector and add to mask array. For example, first-name becomes .first-name. Regexes can be moved as-is.
maskSelectormaskThe selector(s) can be moved directly in the mask array.
ignoreClassignoreConvert the class name to a CSS selector and add to ignore array. For example, first-name becomes .first-name. Regexes can be moved as-is.

Privacy

There are several ways to deal with PII. By default, the integration will mask all text content with * and block all media elements (img, svg, video, object, picture, embed, map, audio). This can be disabled by setting maskAllText to false. It is also possible to add the following CSS classes to specific DOM elements to prevent recording its contents: sentry-block, sentry-ignore, and sentry-mask. The following sections will show examples of how content is handled by the differing methods.

Masking

Masking replaces the text content with something else. The default masking behavior is to replace each character with a *. In this example the relevant html code is: <table class="sentry-mask">...</table>. Masking example

Blocking

Blocking replaces the element with a placeholder that has the same dimensions. The recording will show an empty space where the content was. In this example the relevant html code is: <table data-sentry-block>...</table>. Blocking example

Ignoring

Ignoring only applies to form inputs. Events will be ignored on the input element so that the replay does not show what occurs inside of the input. In the below example, notice how the results in the table below the input changes, but no text is visible in the input.

https://user-images.githubusercontent.com/79684/192815134-a6451c3f-d3cb-455f-a699-7c3fe04d0a2e.mov

Error Linking

Currently, errors that happen on the page while a replay is running are linked to the Replay, making it as easy as possible to jump between related issues/replays. However, please note that it is possible that the error count reported on the Replay Detail page does not match the actual errors that have been captured. The reason for that is that errors can be lost, e.g. a network request fails, or similar. This should not happen to often, but be aware that it is theoretically possible.

Manually sending replay data

You can use replay.flush() to immediately send all currently captured replay data. When Replay is currently in buffering mode, this will send up to the last 60 seconds of replay data, and also continue sending afterwards, similar to when an error happens & is recorded.

7.119.1

3 months ago

7.119.2

2 months ago

7.118.0

6 months ago

7.119.0

4 months ago

7.117.0

6 months ago

7.116.0

7 months ago

7.115.0

7 months ago

7.114.0

8 months ago

7.113.0

8 months ago

7.112.2

8 months ago

7.112.0

8 months ago

7.112.1

8 months ago

7.111.0

8 months ago

7.110.1

8 months ago

7.110.0

8 months ago

7.109.0

9 months ago

8.0.0-alpha.5

9 months ago

7.108.0

9 months ago

8.0.0-alpha.3

9 months ago

8.0.0-alpha.4

9 months ago

7.107.0

9 months ago

7.106.1

9 months ago

7.106.0

10 months ago

8.0.0-alpha.2

10 months ago

8.0.0-alpha.1

10 months ago

7.105.0

10 months ago

7.104.0

10 months ago

7.103.0

10 months ago

7.102.1

10 months ago

7.102.0

10 months ago

7.101.1

10 months ago

7.101.0

10 months ago

7.100.1

11 months ago

7.100.0

11 months ago

7.99.0

11 months ago

7.97.0

11 months ago

7.96.0

11 months ago

7.98.0

11 months ago

7.95.0

11 months ago

7.94.0

11 months ago

7.94.1

11 months ago

7.93.0

12 months ago

7.92.0

12 months ago

7.91.0

1 year ago

7.90.0

1 year ago

7.89.0

1 year ago

7.88.0

1 year ago

7.87.0

1 year ago

7.86.0

1 year ago

7.82.0

1 year ago

7.63.0

1 year ago

7.67.0

1 year ago

7.70.0-beta.0

1 year ago

7.70.0-beta.1

1 year ago

7.70.0

1 year ago

7.74.1

1 year ago

7.74.0

1 year ago

7.66.0-alpha.0

1 year ago

7.78.0

1 year ago

7.59.1

1 year ago

7.59.2

1 year ago

7.59.3

1 year ago

7.64.0-alpha.0

1 year ago

7.81.1

1 year ago

7.81.0

1 year ago

7.85.0

1 year ago

7.62.0

1 year ago

7.66.0

1 year ago

7.73.0

1 year ago

7.58.0

1 year ago

7.58.1

1 year ago

7.77.0

1 year ago

7.80.1

1 year ago

7.80.0

1 year ago

7.65.0-alpha.0

1 year ago

7.61.1

1 year ago

7.84.0

1 year ago

7.61.0

1 year ago

7.65.0

1 year ago

7.69.0

1 year ago

7.74.2-alpha.1

1 year ago

7.74.2-alpha.0

1 year ago

7.67.0-beta.0

1 year ago

7.72.0

1 year ago

7.76.0

1 year ago

7.60.0

1 year ago

7.64.0

1 year ago

7.83.0

1 year ago

7.60.1

1 year ago

7.68.0

1 year ago

7.80.2-alpha.1

1 year ago

7.80.2-alpha.0

1 year ago

7.71.0

1 year ago

7.75.0

1 year ago

7.79.0

1 year ago

7.75.1

1 year ago

7.59.0-beta.1

1 year ago

7.59.0-beta.0

1 year ago

7.57.0

1 year ago

7.51.0

2 years ago

7.51.1

2 years ago

7.51.2

2 years ago

7.55.0

2 years ago

7.55.1

2 years ago

7.55.2

2 years ago

7.57.0-beta.0

2 years ago

7.54.0

2 years ago

7.53.0

2 years ago

7.53.1

2 years ago

7.52.0

2 years ago

7.52.1

2 years ago

7.56.0

2 years ago

7.40.0

2 years ago

7.48.0

2 years ago

7.44.0

2 years ago

7.44.1

2 years ago

7.44.2

2 years ago

7.47.0

2 years ago

7.43.0

2 years ago

7.50.0

2 years ago

7.42.0

2 years ago

7.46.0

2 years ago

7.41.0

2 years ago

7.49.0

2 years ago

7.45.0

2 years ago

7.36.0

2 years ago

7.39.0

2 years ago

7.35.0

2 years ago

7.38.0

2 years ago

7.37.0

2 years ago

7.37.2

2 years ago

7.37.1

2 years ago

7.25.0

2 years ago

7.29.0

2 years ago

7.32.1

2 years ago

7.32.0

2 years ago

7.24.2

2 years ago

7.24.1

2 years ago

7.28.0

2 years ago

7.24.0

2 years ago

7.28.1

2 years ago

7.31.0

2 years ago

7.31.1

2 years ago

7.27.0

2 years ago

7.30.0

2 years ago

7.34.0

2 years ago

7.34.0-beta.0

2 years ago

7.26.0

2 years ago

7.33.0

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.12-0

2 years ago

0.6.14-3

2 years ago

0.6.10-0

2 years ago

0.6.14-2

2 years ago

0.6.14-1

2 years ago

0.6.14-0

2 years ago

0.6.10

2 years ago

0.6.11

2 years ago

0.6.4-0

2 years ago

0.6.14

2 years ago

0.6.13

2 years ago

0.6.13-0

2 years ago

0.6.11-0

2 years ago

0.6.14-6

2 years ago

0.6.14-5

2 years ago

0.6.14-4

2 years ago

0.6.7-0

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.5.10

2 years ago

0.5.11

2 years ago

0.5.18

2 years ago

0.5.19

2 years ago

0.5.16

2 years ago

0.5.17

2 years ago

0.5.14

2 years ago

0.5.15

2 years ago

0.5.12

2 years ago

0.5.13

2 years ago

0.5.6

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.5.21

2 years ago

0.5.22

2 years ago

0.5.20

2 years ago

0.5.23

2 years ago

0.6.0

2 years ago

0.4.8-0

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.4.8-3

2 years ago

0.4.8-2

2 years ago

0.4.8-1

2 years ago

0.2.0-19

2 years ago

0.2.0-18

2 years ago

0.2.0-17

3 years ago

0.2.0-16

3 years ago

0.2.0-15

3 years ago

0.3.0

2 years ago

0.5.4

2 years ago

0.4.5

2 years ago

0.5.3

2 years ago

0.4.7

2 years ago

0.5.5

2 years ago

0.4.6

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.2.0-11

3 years ago

0.2.0-14

3 years ago

0.2.0-13

3 years ago

0.2.0-6

3 years ago

0.2.0-10

3 years ago

0.2.0-5

3 years ago

0.2.0-4

3 years ago

0.2.0-3

3 years ago

0.2.0-2

3 years ago

0.2.0-1

3 years ago

0.2.0-9

3 years ago

0.2.0-8

3 years ago

0.2.0-7

3 years ago

0.2.0-0

3 years ago