tracekit-session-replay
TraceKit Session Replay
When To Use
Use this skill when the user asks to:
- Record user sessions for debugging
- Replay what a user did before an error
- Set up visual debugging or session recording
- See what users did on the page
- Debug user-reported issues visually
- Add session replay to a frontend app
Session replay is a browser-only feature. It records DOM mutations, user interactions, and network requests to reconstruct a video-like replay of user sessions. Replays are linked to distributed traces so you can see the full backend context for any user action.
Non-Negotiable Rules
- Never hardcode API keys in code. Always use environment variables or build-time injection.
- Always enable privacy settings by default --
maskAllText: trueandblockAllMedia: truemust be the starting configuration. - Always include a verification step confirming replays appear in
https://app.tracekit.dev/replays. - Always discuss GDPR/privacy implications before enabling replay -- session recordings capture user behavior and may be subject to data protection regulations.
Prerequisites
Session replay requires a frontend SDK to be installed and initialized. Complete one of the following SDK skills first:
tracekit-browser-sdk-- Vanilla JavaScript/TypeScripttracekit-react-sdk-- React applicationstracekit-vue-sdk-- Vue applicationstracekit-angular-sdk-- Angular applicationstracekit-nextjs-sdk-- Next.js applicationstracekit-nuxt-sdk-- Nuxt applications
Session replay is a BROWSER-ONLY feature. It does not apply to backend SDKs (Node.js, Go, Python, etc.). If the user is working on a backend project, this skill does not apply.
Detection
Before applying this skill, verify a frontend TraceKit SDK is installed:
- Check
package.jsonfor any TraceKit frontend package:@tracekit/browser-- vanilla JS/TS@tracekit/react-- React@tracekit/vue-- Vue@tracekit/angular-- Angular@tracekit/nextjs-- Next.js@tracekit/nuxt-- Nuxt
- If none found, redirect to
tracekit-browser-sdkskill (or the appropriate framework skill) to install the SDK first. - Check if replay is already configured -- search for
@tracekit/replayinpackage.jsonorreplayIntegrationin source files.
Step 1: Install Replay Integration
npm install @tracekit/replay
The replay integration is a separate package that adds session recording capabilities to your existing TraceKit browser SDK.
Step 2: Add Replay to SDK Init
Add the replay integration to your TraceKit initialization:
import { init } from '@tracekit/browser';
import { replayIntegration } from '@tracekit/replay';
const replay = replayIntegration({
// Privacy defaults -- ALWAYS start with these enabled
maskAllText: true,
blockAllMedia: true,
maskAllInputs: true,
networkCaptureBodies: false,
networkDetailAllowUrls: [],
});
init({
apiKey: import.meta.env.VITE_TRACEKIT_API_KEY,
serviceName: 'my-frontend-app',
endpoint: 'https://app.tracekit.dev/v1/traces',
enableCodeMonitoring: true,
addons: [replay],
});
Step 3: Privacy Configuration
This is the most critical section. Session replay records user interactions, so privacy must be configured carefully before deploying to production.
Text Masking
| Setting | Default | Description |
|---|---|---|
maskAllText: true |
true | Replaces all text content with asterisks (****). Strongly recommended. |
maskAllInputs: true |
true | Masks form input values (passwords, emails, search queries). |
unmask: ['.public-content'] |
[] |
CSS selectors for elements safe to show unmasked. Use sparingly. |
mask: ['.sensitive-class'] |
[] |
CSS selectors for additional elements to mask (supplements maskAllText). |
Media Blocking
| Setting | Default | Description |
|---|---|---|
blockAllMedia: true |
true | Blocks images, videos, canvas elements from recording. Strongly recommended. |
block: ['.private-element'] |
[] |
CSS selectors for elements to block entirely (removed from recording). |
Network Capture
| Setting | Default | Description |
|---|---|---|
networkCaptureBodies: false |
false | Capture HTTP request/response bodies. Enable with extreme caution -- may capture sensitive data. |
networkDetailAllowUrls: [] |
[] |
URLs to capture request/response details for. Empty array means none. |
Example: Selective network capture for your own API only:
const replay = replayIntegration({
maskAllText: true,
blockAllMedia: true,
maskAllInputs: true,
networkCaptureBodies: true,
networkDetailAllowUrls: [
'https://api.myapp.com', // Only capture bodies for your own API
],
});
GDPR Considerations
Session replay records user behavior and may be subject to GDPR, CCPA, or other data protection regulations:
- Consent required -- Display a consent banner before enabling session replay. Only start recording after the user consents.
- Data retention -- Configure retention in the dashboard (Settings > Data Retention). Default is 30 days.
- Right to deletion -- Users can request deletion of their session data. Use the TraceKit API to delete sessions by user ID.
- Data processing agreement -- Ensure your TraceKit DPA covers session replay data.
- Privacy policy -- Update your privacy policy to mention session recording.
Conditional initialization based on consent:
import { init } from '@tracekit/browser';
import { replayIntegration } from '@tracekit/replay';
// Only add replay if user has consented
const addons = [];
if (userHasConsentedToRecording()) {
addons.push(replayIntegration({
maskAllText: true,
blockAllMedia: true,
maskAllInputs: true,
}));
}
init({
apiKey: import.meta.env.VITE_TRACEKIT_API_KEY,
serviceName: 'my-frontend-app',
endpoint: 'https://app.tracekit.dev/v1/traces',
enableCodeMonitoring: true,
addons,
});
Step 4: Sampling Configuration
Control how many sessions are recorded to manage storage costs and volume.
const replay = replayIntegration({
// Sampling
replaysSessionSampleRate: 0.1, // Record 10% of all sessions
replaysOnErrorSampleRate: 1.0, // Record 100% of sessions with errors
// Privacy
maskAllText: true,
blockAllMedia: true,
maskAllInputs: true,
});
Two-Tier Sampling Strategy
| Setting | Default | Purpose |
|---|---|---|
replaysSessionSampleRate |
0.1 (10%) |
General session recording for understanding user behavior. |
replaysOnErrorSampleRate |
1.0 (100%) |
Always record sessions where errors occur -- these are the most valuable for debugging. |
How it works:
- A session starts as a "general" session, sampled at
replaysSessionSampleRate - If an error occurs during the session, it is promoted to an "error" session and always captured (if
replaysOnErrorSampleRateallows) - Error sessions include a replay buffer of events before the error, so you see what led up to it
Cost implications:
- Higher
replaysSessionSampleRate= more storage = higher bill - Start with
0.1(10%) for general sessions and1.0(100%) for error sessions - Adjust based on traffic volume and budget
Additional Replay Settings
| Setting | Default | Description |
|---|---|---|
minReplayDuration |
5000 (5s) |
Minimum session duration to record. Short sessions are discarded. |
maxReplayDuration |
3600000 (1h) |
Maximum recording duration. Long sessions are split. |
Step 5: Linking Replays to Traces
When both session replay and distributed tracing are enabled, they are linked automatically. No additional configuration needed.
View a Replay from a Trace
- Open a trace in
https://app.tracekit.dev/traces - If the trace originated from a browser session with replay, a "View Replay" button appears in the trace detail header
- Click to jump to the replay at the exact moment the traced request occurred
View a Trace from a Replay
- Open a replay in
https://app.tracekit.dev/replays - The replay timeline shows event markers for errors, network requests, and console logs
- Click any event marker to see details, including the Trace ID
- Click the Trace ID to jump to the full distributed trace waterfall
Filter Replays
Use the replay list to find specific sessions:
- By error type -- find all sessions where a specific error occurred
- By user -- find all sessions for a specific user (requires
setUser()in SDK) - By time range -- find sessions during an incident window
- By URL -- find sessions that visited a specific page
Step 6: Verification
Verify session replay is working:
- Start your application with replay configured
- Navigate through a few pages and interact with the UI (clicks, form inputs, page transitions)
- Visit
https://app.tracekit.dev/replays - Find your session in the replay list (most recent, filtered by your user or time)
- Click to play the replay
- Verify privacy settings:
- Text should appear as
****(ifmaskAllText: true) - Images and videos should be blocked (if
blockAllMedia: true) - Form inputs should be masked (if
maskAllInputs: true)
- Text should appear as
- Click an error marker (if any) to verify it links to a distributed trace
Troubleshooting
Replays not appearing
- Check sampling rate --
replaysSessionSampleRate: 0.1means only 10% of sessions are recorded. Set to1.0during testing. - Check replay integration is added -- verify
@tracekit/replayis inpackage.jsonandreplayIntegration()is passed toaddons. - Check browser console for errors from the TraceKit SDK. Enable
debug: truein init config for verbose logging. - Check Content Security Policy -- CSP must allow connections to
https://app.tracekit.dev.
All text visible (not masked)
- Verify
maskAllText: trueis set in the replay integration config. - Check for
unmaskselectors -- elements matchingunmaskpatterns are shown in clear text. - Rebuild and redeploy -- config changes require a new deployment to take effect.
Replay too short or cutting off
- Check
minReplayDuration-- sessions shorter than this threshold are discarded (default 5 seconds). - Check
maxReplayDuration-- sessions longer than this are split into segments. - Check if user navigated away -- replay stops when the user closes the tab or navigates to an external site.
Large replay file sizes
- Lower
replaysSessionSampleRateto reduce total recorded sessions. - Enable
blockAllMedia: trueto exclude images and videos from recordings. - Reduce
networkCaptureBodiestofalseif enabled -- request bodies add significant size.
Next Steps
Once session replay is working, consider:
- Source Maps (
tracekit-source-mapsskill) -- See readable stack traces in replay error markers instead of minified code - Alerts (
tracekit-alertsskill) -- Get notified when replay-captured errors spike
References
- Session replay docs:
https://app.tracekit.dev/docs/frontend/session-replay - TraceKit docs root:
https://app.tracekit.dev/docs - Dashboard:
https://app.tracekit.dev