Skip to Content
OpenPerf

Guides

Session replay

Record what users see and do in the browser, choose which sessions to keep and what stays hidden.

The browser SDK can record sessions as replays: the page's DOM and its changes, scrolls, clicks and typing, plus the console lines, requests and errors of the session. Recording is off until you set a sample rate.

main.ts
import { init } from "@openperf/sdk/browser";

init({
  dsn: import.meta.env.VITE_OPENPERF_DSN,
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1,
});

Choose sessions

OptionDefaultRecords
replaysSessionSampleRate0This share of sessions, from the first page on
replaysOnErrorSampleRate0This share of the other sessions, starting up to two minutes before their first error

The SDK decides once, when a session starts. A session lives in one browser tab, carries over page loads in it and ends after 30 minutes without activity or after an hour; the next page starts a new one. With a DSN set, a rate outside 0 to 1 makes init throw a RangeError.

An on-error session keeps the last minute or two in memory and sends nothing until an error is reported, by an uncaught error or captureException. From then on it records like a sampled session. Errors dropped by ignoreErrors, denyUrls or beforeSend don't start it.

Hide content

By default all text on the page turns into asterisks, and so does the value of every text field, select and textarea. Images, video, audio, canvas and SVG become empty boxes of the same size.

The rest is recorded as it is: attributes such as placeholder, title, aria-label, href and data-*, the values of hidden inputs, checkboxes and radio buttons, the name of a chosen file, the captions of input buttons and the prefilled value of a field the user has emptied. Block an element that keeps private data in any of these.

To block elements or to show more, pass replay:

main.ts
init({
  dsn: import.meta.env.VITE_OPENPERF_DSN,
  replaysSessionSampleRate: 0.1,
  replay: {
    maskAllText: false,
    mask: [".customer-name"],
    block: ["#card-form"],
    ignore: ["#search"],
  },
});

Prop

Type

Two attributes work in markup without changing init:

AttributeEffect
data-openperf-maskHides the element's text when maskAllText is false
data-openperf-blockAlways replaces the element with an empty box of its size

Page URLs go through the project's query filter on ingest, like the URLs of spans. See Inbound filters.

How data is sent

A sampled session sends a gzipped segment to /v1/replays on the DSN host every five seconds and when the page is hidden. If your site sets a Content Security Policy, the DSN host in connect-src covers it.

A segment that doesn't reach ingest, because the network is down or ingest answers with a server error, is dropped and recording pauses. The first change on the page after five seconds resumes it from a fresh snapshot; what happened in between is missing from the replay. Each further failure doubles the wait, up to a minute; a segment that gets through resets it.

A project can send up to 256 MiB of replay data a minute. A session that goes over it stops recording; what it sent before stays. Replays are kept for 30 days.

Backend errors and logs appear in the replay when the session's requests carry the trace on. See Distributed tracing.

On this page