Configure Session Capture
Session replay shows what a user saw and did on the page: before an error, along a journey you care about, or while they tell support about a problem. This page sets it up from the first line of code to the dashboard. Private content is hidden in the browser, before anything is uploaded, and once the app ships you change what is recorded from the dashboard, without a release.
| Step | What you do | Where |
|---|---|---|
| 1. Turn on replay and set the limits | Start the SDK and decide what may never be recorded | Your code |
| 2. Hide private content | Keep inputs masked and mark private elements | Your markup |
| 3. Choose whether replays show images | Pick off, wifi or always | Your code or a rule |
| 4. Choose which sessions upload replay | Keep the error clips, sample sessions, record journeys | Your code or a rule |
| 5. Capture one user or device | Identify users, then capture one when they report a problem | Your code, then the dashboard |
| 6. Change collection remotely | Write Data Collection rules | The dashboard |
With Steps 1 and 2 done, every captured error uploads a 30-second replay clip. The other steps change what is recorded and when it is uploaded.
This page uses @tracewayapp/react. Session Replay is the reference.
Step 1: Turn on replay and set the limits in the app
The browser SDK records the page itself. rrweb, an open-source recorder, captures the DOM and every change to it, and the player in Traceway rebuilds the page from that recording: no screenshots and no video. The recorder runs in the tab and keeps what it records in the tab's memory. Nothing is uploaded until an error, a trigger or a capture asks for it (Step 4).
Replay is on by default, so starting the SDK is enough. The options below only make the limits explicit:
import { TracewayProvider } from "@tracewayapp/react";
export function App() {
return (
<TracewayProvider
token={import.meta.env.VITE_TRACEWAY_TOKEN}
options={{
version: "1.4.2",
sessionRecording: true, // the default; false means no replay, whatever a rule says
collection: {
replay: { maskAllInputs: true, images: "wifi" },
},
}}
>
<YourApp />
</TracewayProvider>
);
}Next.js reads the token from process.env.NEXT_PUBLIC_TRACEWAY_TOKEN. The provider reads its props once, when it mounts.
The options the SDK starts with are ceilings: a rule or a capture from the dashboard can keep a signal on the device or switch it off, but it never turns on what the app turned off. These are the ones that matter for replay:
| Option | Default | What it limits |
|---|---|---|
sessionRecording | true | false means no replay at all. The recorder is never loaded, whatever a rule, a trigger or a capture says |
replayImages | "always" | The most the replay records of pictures: "off" (empty boxes), "wifi" (their URLs) or "always" (also small copies). replay.images from collection or a rule applies only up to it (Step 3) |
captureLogs, captureNetwork, captureNavigation, captureUserActions | true | The console lines, requests, page changes and clicks the player shows next to the replay. false removes one from every session, uploads included |
collectionLimits | 50 MiB and 10,000 events | What one session may upload in all, replay events included. It can only be lowered |
Leave sessions on: the Sessions page lists the sessions the SDK reports.
The recording waits in memory in segments of 30 seconds (sessionRecordingSegmentDuration), each starting with a full snapshot of the page, so every segment plays on its own. The buffer keeps at most 8 MiB (collection.buffer.replayMaxBytes) and 10 minutes (collection.buffer.maxAgeSeconds). An error clip takes the last 30 seconds of it; a trigger or a capture can take more, as far back as the buffer still reaches. The buffer starts empty on every full page load.
collection takes the same settings document as a Data Collection rule (Step 6), so the examples on this page show that document as JSON. Put it in collection to set it in the app, or in a rule's JSON tab to set it from the dashboard. A rule wins over collection, and the ceilings win over both. One field of collection is a floor instead: replay.maskAllInputs: true there keeps inputs masked whatever a rule says (Step 2).
When the page needs the user's consent before it may record, start the SDK after consent, or start it with sessionRecording: false.
Step 2: Hide private content
Inputs are masked by default
With replay.maskAllInputs on, which is the default, the value of every input, textarea and select is recorded as *. With it off, only password fields are. It is a collection setting:
{ "replay": { "maskAllInputs": true } }Set to true in the app's collection, it is a floor: a rule's "maskAllInputs": false leaves the inputs masked. Left out of collection, inputs are masked by default and a rule can switch masking off; set to false there, a rule can switch it on. A field that must stay hidden even with maskAllInputs off belongs inside an element with traceway-mask or traceway-blank (next section). A change of maskAllInputs restarts the recorder and drops the buffered replay recorded with the old setting.
Mark elements with a mask
Add a class to the markup; no code is needed. The browser SDK has no mask API: these two classes are all there is.
| Class | What the replay shows |
|---|---|
traceway-mask | The element and its layout. Its text is recorded with every character except whitespace replaced by *, and so are the attribute values that carry text (title, alt, aria-*, data-*, placeholder, label, href, value) and what is typed into its fields, even with maskAllInputs off. Its img, picture, video, canvas and svg elements are empty boxes of their size, without a source URL, and pictures in a style attribute become none |
traceway-blank | An empty box of the element's size. Nothing inside it is recorded: no text, no images, no input values and no input events |
In JSX the attribute is className:
function AccountCard({ user, card }) {
return (
<section>
<p className="traceway-mask">
Card ending {card.last4}, {user.name}
</p>
<div className="traceway-mask">
<img src={user.avatarUrl} alt="" /> {user.name}
</div>
<div className="traceway-blank">
<SignaturePad />
</div>
</section>
);
}Card ending 4242, Alice Smith replays as **** ****** ***** ***** *****. Render the class with the element, not from an effect after it mounted.
The mask reaches into shadow roots and same-origin iframes inside the element, also for text they render or change after recording started. It does not hide:
- pictures that a stylesheet sets (a class with
background-image), which the replay loads by their URL. Put such an element insidetraceway-blank; - what the element showed before it got the class, until the next full snapshot, at most 30 seconds later. Put the class in the markup from the start.
Masked data-* and aria-* values can change how the masked area looks in the replay when the page's CSS selects on them. rrweb's own classes keep working: rr-mask masks text like traceway-mask but leaves images as they are, rr-block records an empty box like traceway-blank, and rr-ignore stops recording an input's events.
Check the mask before you ship
A mask that does not apply fails quietly: a misspelled class records the text as it is. Look at a real replay of every page that shows private data before you ship it:
- In a development build, add
recordAllSessions: trueto the options, so every session streams its replay. - Open the pages with private data and type into their fields. Then switch to another tab, which uploads the segment in progress.
- In Traceway, open Sessions, open your session and play it. Masked text shows as
*, blank elements are empty boxes, and typed values are*.
Remove recordAllSessions before you ship. Check again after a change to those pages; to check in production, capture your own browser (Step 5).
Step 3: Choose whether replays show images
replay.images decides what the replay shows of pictures outside a mask. It is a collection setting, set in collection or with a rule's Replay images select:
| Value | What the replay shows |
|---|---|
"off" | Every img, picture, SVG image and <input type="image"> as an empty box of its size, without its URL |
"wifi" (default) | The pictures, loaded from their URLs when the replay plays. No pixels are uploaded |
"always" | The same, plus a small copy of each picture the page may read (from its own origin, or from another origin that serves it with CORS), so the replay shows it even when the URL no longer works |
{ "replay": { "images": "always" } }The app's replayImages option is its ceiling ("always" by default), as on the app SDKs: the lower of the two applies, in the order off, wifi, always. A rule's value replaces the one in collection, but never goes past replayImages: with replayImages: "off" every picture stays an empty box whatever a rule says, and with "wifi" a rule's "always" adds no copies. Without replay (sessionRecording: false) the policy is "off".
A picture that must never be recorded belongs inside traceway-mask or traceway-blank, which no setting changes. "off" does not touch video and canvas elements either; mask those. The browser cannot tell Wi-Fi from a metered connection, so "wifi" behaves like the app SDKs on a metered connection: URL references only.
With "always", each loaded <img> is copied at its displayed size. A picture with transparency becomes a PNG of at most 192 px on its longest side, because JPEG would replay its transparent pixels as black; any other picture becomes a JPEG at quality 0.45 of at most 384 px. A copy over 48 KiB is tried once at half the size and otherwise left as a URL. The SDK keeps up to 128 copies for the next snapshots, adds at most 4 MiB of them to a session's recording, and spends at most 16 ms on them per snapshot. Copies go into full snapshots only, the one that starts each segment and the one when a hidden page comes back: a picture that appears later keeps its URL until the next snapshot. Where the browser allows it, the copies are made in a Worker of the SDK's own, off the page's main thread. It never changes the page's own <img> elements, so a picture from another origin without CORS stays a URL reference.
A segment carries at most 128 KiB of copies. One that would carry more is recorded without copies, with the URL references "wifi" records, and the next segment starts with a fresh allowance. So "always" never shows fewer pictures than "wifi", but on a page full of pictures it may add none.
A change of replay.images restarts the recorder and drops the buffered replay recorded with the old value. Each session reports the value that applies, ceiling included, as traceway.replay.images, and the bytes of the copies added so far as traceway.replay.image_bytes.
Step 4: Choose which sessions upload replay
What uploads by default
Without rules, the SDK keeps the replay and the breadcrumbs (console lines, requests, page changes, clicks) on the device. For each captured exception, the built-in error trigger default-exception uploads the last 10 minutes of breadcrumbs and a 30-second replay clip. Clips have a 5-second cooldown and a limit of 20 per session: an error inside the cooldown or past the limit still uploads its breadcrumbs, without a clip. A message from captureMessage uploads no clip, and an exception that ignoreErrors, beforeCapture or the error limit drops uploads nothing.
The issue page plays the clip next to the error. When there is none, the error's event says why: replay off, a disabled trigger, the cooldown, the clip limit, sampling, an empty buffer or a used-up session budget.
To stop the error clips, switch the trigger off:
{ "triggers": [{ "id": "default-exception", "enabled": false }] }Record every session or a sample
Three settings upload more than the error clips, from the most data to the least:
-
recordAllSessions: true, an option of the app, streams every replay segment and every breadcrumb of every session. Use it in development, or in a small app. -
Replay streaming for a share of sessions, in
collectionor a rule. The share is decided per session id, so a session is recorded whole or not at all, and the other sessions keep their error clips:{ "replay": { "mode": "stream", "sessionSampleRate": 0.1 } } -
baselineSampleRate, an option of the app or a rule's Healthy session sample (%), streams the breadcrumbs and request spans of a share of sessions, without replay.0.01(1%) gives a stable sample of healthy visits.
A streamed session uploads each 30-second segment when it ends, and the segment in progress when the tab is hidden. All uploads of a session share one budget, 50 MiB and 10,000 events (collectionLimits); past it, the SDK drops diagnostics and counts what it dropped.
Record a journey with a trigger
A recording trigger watches for steps in order on the same tab, then uploads the replay it buffered and keeps recording for a while. Build one in a rule's Triggers tab (Step 6 shows how to open a rule):
- Click Add recording trigger and enter a Trigger name, such as
Checkout failed. Sessions it records show that name. - Add up to five steps with Add step. Each step is an Event:
- Click or Hover with a CSS selector (next section);
- Navigation with a route pattern such as
/orders/{id}, where{id}matches one path segment; - Log with a log message, which Exactly matches or Contains the line.
- Set Within seconds of previous step where the steps must follow each other quickly, then Replay lookback (seconds), Continue recording (seconds), Cooldown (seconds) and Captures per session.
- Save the rule.
Below the recording triggers, Capture when a log line appears starts a capture when a line repeats, for example payment failed 3 times within 60 seconds, and streams for a number of minutes, with or without replay.
A Log step matches a console.* line, a log() line or a message from captureMessage. Give the moments you want to find a line of their own:
import { log, captureMessage } from "@tracewayapp/react";
async function pay(order) {
const result = await submitPayment(order);
if (result.declined) {
log("Payment declined", "warn", { provider: "stripe" }); // matches a Log step "Payment declined"
}
if (result.abandoned) {
captureMessage("Checkout abandoned"); // also opens an issue
}
}The text is compared as it is, so keep it constant and put the parts that change in attributes. A trigger the builders cannot express goes in the rule's JSON tab, whose Add a trigger buttons hold templates such as Failed requests and Custom event (a track() name). See Triggers for every field, and Record the journeys that matter for more examples.
Name the elements a trigger can match
A Click or Hover step matches when the element under the pointer, or one of its ancestors, matches the step's CSS selector, so a click on a button's icon still counts for the button. Selectors take tags, ids, classes, attributes and the descendant, child and sibling combinators. Pseudo-classes such as :hover, lists with commas and escaped characters are not supported.
Generated ids and utility classes change between builds, so give each control a trigger needs a stable name:
<button id="place-order" data-testid="place-order">Place order</button>The step's selector is then #place-order or [data-testid="place-order"]. Quote attribute values, and leave out anything personal, such as a user's name. A data-testid also names the control in the slow-interaction metrics (stable element names).
Name your pages
A Navigation step matches the path of the page, without its query or fragment, and is case-sensitive: /orders/{id} matches /orders/42, not /orders/42/edit or /Orders/42. Navigation inside a single-page app counts, and so does a full page load in the same tab.
Name pages by their route template as well. Replays, issues and log lines then say which screen the user was on (app.screen.name, for example /orders/:id), and performance metrics group by route. Route templates write a parameter as :id; Navigation steps write it as {id}.
React Router in framework mode, Remix, TanStack Router and the Next.js Pages Router need no code. A React Router data router goes to the provider; with <BrowserRouter> and <Routes>, or the Next.js App Router, call useTracewayRoute with the path and its params:
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { TracewayProvider } from "@tracewayapp/react";
const router = createBrowserRouter(routes);
<TracewayProvider token={import.meta.env.VITE_TRACEWAY_TOKEN} router={router}>
<RouterProvider router={router} />
</TracewayProvider>;// React Router with <Routes>: a layout route sees the params of the page below it
import { Outlet, useLocation, useParams } from "react-router-dom";
import { useTracewayRoute } from "@tracewayapp/react";
function Layout() {
useTracewayRoute(useLocation().pathname, useParams());
return <Outlet />;
}For navigation the address does not show (a modal, a wizard step, a memory router), report it. Its path is what a Navigation step matches:
import { recordNavigation } from "@tracewayapp/react";
recordNavigation(
"/checkout/payment",
"push",
"/checkout/address",
"/checkout/:step",
);Route Names has the Next.js App Router component and the other forms.
Step 5: Capture one user or device from the dashboard
A capture makes one browser upload what it buffered, then stream everything, replay included, for up to 24 hours. It targets a device, a user, a session or any attribute. To capture a user, the SDK has to know who they are: set user.id after sign-in, then ask for the settings at once, so a capture or a rule for that user applies without waiting for the next poll:
import { useEffect } from "react";
import { useTracewayAttributes, refreshConfig } from "@tracewayapp/react";
function SignedInShell({ user, children }) {
useTracewayAttributes(user ? { "user.id": String(user.id) } : null);
useEffect(() => {
if (user) refreshConfig();
}, [user?.id]);
return children;
}Every browser profile also has a device id, service.instance.id, which getInstanceId() returns and every session shows among its attributes. A support page can display it for the user to read out.
Then, in Traceway:
- Open the user's session and click Capture this device, or click Capture device on an issue's event. Otherwise open Data Collection in the project's sidebar and click New Capture under Captures.
- Choose the Target: Device (instance id), User (user.id), Session or Attribute, and enter its Value.
- Choose how long it runs (For, up to 24 hours) and what it uploads first (Include: nothing earlier, the last minute, the last 10 minutes or the last hour).
- Leave Record session replay on and click New Capture.
The browser picks the capture up at its next poll, within 5 minutes, or when the tab becomes visible again after its polling interval; refreshConfig() polls at once. While a capture runs, the browser polls every minute. Each tab uploads the lookback once per capture, then streams until the capture ends or someone cancels it in the Captures list. A project can have 20 captures running at once, and a capture never turns on what the app's ceilings turned off.
Step 6: Change collection remotely with Data Collection rules
A rule changes what a group of browsers collects while the app runs. It holds the same settings document as collection, and applies to the browsers whose attributes match its conditions.
-
Open the project in Traceway and click Data Collection in the sidebar. The page lists the rules, in the order they apply, and the captures below them.
-
Click New Rule and give it a Name.
-
In Applies to, add the conditions a browser must match: a key such as
service.version,browser.name,user.idor an attribute you set, an operator (equals, is one of, version matches, ...) and a value. Roll out to limits the rule to a share of the matching browsers, and a browser stays in or out as long as the share does not drop. With no condition, the rule applies to every browser of the project.
-
In Signals, set what this rule changes and leave the rest on Inherit. For replay: Session replay (Off, Buffer or Stream), Replay images (Off, Wi-Fi only or Always) and Healthy session sample (%).
-
In Triggers, add the recording triggers of Step 4.
-
In JSON, edit the whole document. Fields the form does not show, such as
replay.sessionSampleRateandreplay.maskAllInputs, are set there. -
Click New Rule to save it.
Preview shows the document a browser with the attributes you enter would get. Browsers pick up a change within about 5 minutes, and when a tab becomes visible again after its polling interval. When two rules set the same field, the one lower in the list wins. A rule can lower what the app collects, or raise it up to the app's ceilings, never past them. The settings reference lists every field.
Check that it works
Send one test error from a development build and follow it into Traceway.
- Start the SDK with
debug: true. The browser console then showsTraceway: started (https://cloud.tracewayapp.com/api/otel/v1/logs), session …, a line for each settings document applied (Traceway: remote config applied (…)), and every exception the SDK drops, with the reason. - Open a page, click around for a few seconds, then capture an error and send it:
import { TracewayProvider, captureException, flush } from "@tracewayapp/react";
<TracewayProvider
token={import.meta.env.VITE_TRACEWAY_TOKEN}
options={{ debug: true }}
>
<YourApp />
</TracewayProvider>;
function TestErrorButton() {
async function send() {
captureException(new Error("Traceway replay test"));
await flush();
}
return <button onClick={send}>Send test error</button>;
}-
In Traceway, open Issues: the test error has a replay clip of the seconds before it. Open Sessions, then the session. The player shows the page as you saw it, with its URL above it, and your clicks, requests and console lines next to it.
-
A session that a trigger recorded has a Recording triggers card with the trigger's name and steps, and the Sessions list filters by it (Recorded by).
-
In Logs, the SDK's own events show what it did:
traceway.config.applied(a settings document was applied),traceway.trigger.fired(a trigger fired, withtraceway.trigger.id) andtraceway.capture.started(a capture started, withtraceway.capture.id). -
The session's Overview shows Failed replay uploads and Diagnostic events dropped, and its attributes include
traceway.replay.imagesandtraceway.replay.image_bytes.
To test without the dashboard, start the SDK with remoteConfig: false and a collection that holds your trigger, or with recordAllSessions: true. Remove both before you ship.
What replay does not record
- Canvas drawings. Charts, maps and games drawn on a
<canvas>replay as an empty canvas. - Cross-origin iframes. A frame from another origin, such as a payment form or an embedded video, replays empty. A same-origin frame is recorded, and masks reach into it.
- What the browser draws itself:
alert()and other dialogs, permission prompts, the address bar and other tabs. - Files by URL. Pictures, videos and fonts are loaded again from their URLs when the replay plays, and so is a stylesheet from another origin that the page cannot read. The replay shows what the URL returns then, or nothing once it needs a login or has expired.
replay.images: "always"keeps copies of pictures only, up to 128 KiB of them in a segment; a segment with more than that keeps the URLs of its pictures without copies. - Earlier pages. The replay buffer lives in the tab's memory and starts empty on every full page load, so an error clip never reaches back into the previous page. Segments uploaded before the load stay uploaded.
- Past the budget. A session uploads at most 50 MiB and 10,000 events of diagnostics in all, replay included, and at most 4 MiB of picture copies. Past that, the SDK drops the rest and counts it (
traceway.collection.health, Diagnostic events dropped). - Other tabs. A session belongs to one tab. It continues across page loads in that tab and ends after 15 minutes without activity or 60 minutes in total.
When it fails
| Symptom | Cause | Fix |
|---|---|---|
The console shows Traceway: init() failed and the SDK is off with init() needs a token | The build has no token: its environment variable is not set | Set the variable (VITE_TRACEWAY_TOKEN, or your framework's public prefix) for that build and build again |
| An issue has no replay | The error came within 5 seconds of the last clip, the session already had 20 clips, replay is off (sessionRecording: false or a rule), or the session's budget is used up | Read the reason on the error's event. To investigate a flow, stream replay with a rule for a while (Step 4) |
| Masked text shows in clear | The class is misspelled, it was added after recording started, or a stylesheet sets the picture | Put the class in the markup from the start; use traceway-blank for pictures set by CSS |
| Pictures are empty boxes | replay.images is "off", the pictures are inside a mask, or the page supplies them as data: URLs, which are never recorded (SVG icons of up to 4,096 characters are) | Check Replay images in the rules and replay.images in collection; serve a picture that must replay from a URL |
| Pictures are broken in the replay | Their URL needs a login or has expired. With "always", a segment with more than 128 KiB of copies keeps URLs only | Set replay.images to "always", which copies same-origin and CORS pictures, up to 128 KiB a segment |
| A trigger never fires | The rule has not reached the tab yet, its conditions do not match this browser, the selector uses a form that is not supported, or the Navigation pattern differs in case or in the number of segments | Call refreshConfig() or wait for the next poll, check the browser with Preview, and check that document.querySelector finds the element with the step's selector |
| A capture never starts | The target does not match what the browser reports, or the browser has not polled since | Compare the value with the session's service.instance.id or user.id; call refreshConfig() after sign-in |
Rules have no effect and debug logs this server has no remote config; local settings apply | The self-hosted Traceway server is older than remote config | Upgrade the server; until then, collection sets the policy |
403 on /api/otel/v1/opamp | The token belongs to a backend project | Use the token of the browser project |
401 on /api/otel/v1/opamp | The token was rejected | Copy the token again from the project's Connection page |