SlideShare a Scribd company logo
Session Replay
Lessons Learned from Building
a DOM capturing product
Wey Wey Web 2023 Francesco Novy
1
About Me
Sentry & Session Replay
How does Session Replay work?
Lessons Learned:
Know your Use Case
Expect the Unexpected
How to Optimize Bundle Size
How to Compress Data
Overview
2
Francesco Novy
hello@fnovy.com
www.fnovy.com
mydea
Living in Vienna, Austria
8+ years of building web UIs
At Sentry since 2022
Working on the JavaScript SDKs
3
4
Error Monitoring
Performance Monitoring
Profiling
Session Replay
What does Sentry do?
5
Capture what's happening in the user's
browser
See what happened leading up to an
error
In-depth debugging similar to the
Browser DevTools
Session Replay
6
Session Replay
7
Session Replay
8
import * as Sentry from '@sentry/browser';
Sentry.init({
integrations: [
new Sentry.Replay({
unmask: ['.show-this-class']
})
],
// Always capture when an error happens
replaysOnErrorSampleRate: 1.0,
// Capture 10% of sessions generally
replaysSessionSampleRate: 0.1,
});
1
2
3
4
5
6
7
8
9
10
11
12
13
How to use Session Replay?
9
We use a fork of
Mutation Observers
Monkey Patching* Stylesheet APIs
Monkey Patching* Canvas APIs
rrweb
How does it work?
10
* What is Monkey Patching?
const originalFetch = window.fetch;
window.fetch = function() {
console.log("A fetch happened!");
return originalFetch.apply(window, arguments);
}
// Later somewhere in the application
window.fetch('https://example.com');
// Will show the console log
1
2
3
4
5
6
7
8
9
"Monkey patching is a technique used to dynamically
update the behavior of a piece of code at run-time."
11
Know your Use Case
Expect the Unexpected
How to Optimize Bundle Size
How to Compress Data
Lessons Learned
12
Know your Use Case
Do we really need that?
13
Know your Use Case
What do you really need?
Hide text & user input by default
Opt-in to show certain text
Defaults matter: Make the best
way the easy way
Make the worst things impossible
14
Expect the Unexpected
Everything that can go wrong, will go wrong.
15
Expect the Unexpected
Low Level APIs are dangerous to tinker with
Monkey Patching is dangerous
Browser Extensions can do anything
try-catch everything
16
How to Optimize Bundle Size
Ship as little code as necessary.
17
Session Replay Bundle Size
Bundle Size v7.73.0: ~53 KB
Bundle Size v7.78.0: ~35 KB
Still large 😱
... but how?
18
Optimizing Bundle Size
Remove unused code from rrweb
Audit dependencies
Make certain recording features
opt-in
Optimize for Tree Shaking!
19
What is Tree Shaking?
describes the ability to
automatically remove unused code from
your build.
When code is written in a tree-shakeable
way, bundlers like Webpack can optimize
your application based on what is actually
used.
Tree Shaking
20
Tree Shaking: Simple Example
// SDK
import { large, small } from './my-code';
export function largeOrSmall(config) {
return config.useLage ? large() : small();
}
// Application
import { largeOrSmall } from 'sdk';
largeOrSmall({ useLarge: false });
1
2
3
4
5
6
7
8
9
10
11
❌Not tree shakeable
21
// SDK
export { large, small } from './my-code';
// Application
import { small } from 'sdk';
small();
1
2
3
4
5
6
7
✅Tree shakeable
Tree Shaking: Simple Example
22
// SDK
import {
CanvasManager
} from './canvas-manager';
export function record(options) {
if (options.recordCanvas) {
new CanvasManager();
}
}
// Application
import { record } from 'sdk';
record({ recordCanvas: false });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
❌Not tree shakeable
Tree Shaking: Actual Example
23
// Application A
import {
record
} from 'sdk';
record({ getCanvasManager: undefined });
1
2
3
4
5
6
✅Tree shakeable
Tree Shaking: Actual Example
// SDK
import {
CanvasManager
} from './canvas-manager';
export function getCanvasManager() {
return new CanvasManager();
}
export function record(options) {
if (options.getCanvasManager) {
options.getCanvasManager();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Application B
import {
record,
getCanvasManager
} from 'sdk';
record({ getCanvasManager });
1
2
3
4
5
6
7
24
How to Compress Data
Avoid unnecessary network traffic, where possible.
25
Compressing Data
Compress data in a web worker
Gracefully handle errors
Make sure to compare libraries
(e.g. )
fflate
26
Web Workers
Setting up the web worker
// worker.js
import { compressSync } from 'fflate';
function handleMessage(e) {
const { input, id } = e.data;
const compressed = compressSync(input);
// Send compressed data back to main thread
postMessage({ id, output: compressed });
}
// Receive uncompressed data from main thread
addEventListener('message', handleMessage);
1
2
3
4
5
6
7
8
9
10
11
12
27
Web Workers
Using the web worker from your application
// Application
const worker = new Worker('/worker.js');
function compressData(data) {
const id = generateUuid();
return new Promise(function (resolve) {
function listener(response) {
if (response.data.id === id) {
worker.removeEventListener('message', listener);
resolve(response.data.output);
}
}
worker.addEventListener('message', listener);
worker.postMessage({ id, input: data });
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
28
https://github.com/getsentry/sentry-javascript
The Sentry SDK is Open
Source!
Everything we do is open source!
Look at the code, PRs, etc.
We love feedback!
29
Thank you!
hello@fnovy.com
www.fnovy.com
mydea
Francesco Novy
30

More Related Content

ODP
Swt 2009
DOCX
software Documentation Certificate in department of computer
PPTX
Use Eclipse technologies to build a modern embedded IDE
PPT
How to implement camera recording for USB webcam or IP camera in C#.NET
ODP
Node js presentation
PDF
Day In A Life Of A Node.js Developer
PDF
Day in a life of a node.js developer
PPTX
Background Tasks with Worker Service
Swt 2009
software Documentation Certificate in department of computer
Use Eclipse technologies to build a modern embedded IDE
How to implement camera recording for USB webcam or IP camera in C#.NET
Node js presentation
Day In A Life Of A Node.js Developer
Day in a life of a node.js developer
Background Tasks with Worker Service

Similar to Lessons Learned from building Session Replay - Francesco Novy (20)

PDF
Browser exploitation SEC-T 2019 stockholm
PDF
RICOH THETA x IoT Developers Contest : Cloud API Seminar
PDF
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
PDF
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
PPTX
Kraken.js Lab Primer
PDF
Lesson 02 - React Native Development Environment Setup
PDF
Programming ASP NET MVC 4 Developing Real World Web Applications with ASP NET...
PDF
NetWeaver Developer Studio for New-Beas
PPTX
Mean stack Magics
PDF
End-to-end web-testing in ruby ecosystem
PDF
XPages Blast - ILUG 2010
PDF
Programming ASP NET MVC 4 Developing Real World Web Applications with ASP NET...
PPT
Monitoring using Prometheus and Grafana
PPTX
Micro-Frontends JSVidCon
PPTX
Advanced Coded UI Testing
PPTX
Introduction to Client Side Dev in SharePoint Workshop
PPTX
React_Complete.pptx
PPTX
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
PDF
How to build a chat application with react js, nodejs, and socket.io
Browser exploitation SEC-T 2019 stockholm
RICOH THETA x IoT Developers Contest : Cloud API Seminar
Learning the iOS 4 SDK for JavaScript Programmers Create Native Apps with Obj...
Learning the iPhone SDK for JavaScript Programmers Create Native Apps with Ob...
Kraken.js Lab Primer
Lesson 02 - React Native Development Environment Setup
Programming ASP NET MVC 4 Developing Real World Web Applications with ASP NET...
NetWeaver Developer Studio for New-Beas
Mean stack Magics
End-to-end web-testing in ruby ecosystem
XPages Blast - ILUG 2010
Programming ASP NET MVC 4 Developing Real World Web Applications with ASP NET...
Monitoring using Prometheus and Grafana
Micro-Frontends JSVidCon
Advanced Coded UI Testing
Introduction to Client Side Dev in SharePoint Workshop
React_Complete.pptx
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
How to build a chat application with react js, nodejs, and socket.io
Ad

More from Wey Wey Web (20)

PDF
Portable, secure, and lightweight: Wasm runtimes and their use-cases - Natali...
PDF
Auditing Design Systems for Accessibility - Anna E. Cook
PDF
Adaptive Designs, Beyond Pixel Perfection - Stephanie Walter
PDF
Sharing is caring: what to know before you build a Research Repository - Juli...
PDF
Unlocking collaboration: A framework for developers and designers - Alicia Ca...
PDF
3 reasons to switch to OKLCH - Anton Lovchikov
PDF
ChatGPT and AI for web developers - Maximiliano Firtman
PDF
Declarative Design - Jeremy Keith - Wey Wey Wey 2023
PDF
Form follows emotion - Isabella De Cuppis
PPTX
UX for emerging tech - Josephine Scholtes
PDF
Collaborative software with State Machines - Laura Kalbag
PDF
Let's get visual. Visual testing in your project - Ramona Schwering
PDF
Solving Common Web Component Problems - Simon MacDonald
PDF
The Future is Malleable - Aleksandra Sikora
PDF
Trending tools & methodologies for UX - Josephine Scholtes.pdf
PDF
Decoding Web Accessibility through Testing - Anuradha Kumari
PDF
Good Security is one question away - Wiktoria Dalach
PDF
Dynamic CSS Secrets - Lea Verou
PDF
The Misty Report - Douglas Crockford
PDF
Web performance optimisations for the harsh conditions - Anna Migas
Portable, secure, and lightweight: Wasm runtimes and their use-cases - Natali...
Auditing Design Systems for Accessibility - Anna E. Cook
Adaptive Designs, Beyond Pixel Perfection - Stephanie Walter
Sharing is caring: what to know before you build a Research Repository - Juli...
Unlocking collaboration: A framework for developers and designers - Alicia Ca...
3 reasons to switch to OKLCH - Anton Lovchikov
ChatGPT and AI for web developers - Maximiliano Firtman
Declarative Design - Jeremy Keith - Wey Wey Wey 2023
Form follows emotion - Isabella De Cuppis
UX for emerging tech - Josephine Scholtes
Collaborative software with State Machines - Laura Kalbag
Let's get visual. Visual testing in your project - Ramona Schwering
Solving Common Web Component Problems - Simon MacDonald
The Future is Malleable - Aleksandra Sikora
Trending tools & methodologies for UX - Josephine Scholtes.pdf
Decoding Web Accessibility through Testing - Anuradha Kumari
Good Security is one question away - Wiktoria Dalach
Dynamic CSS Secrets - Lea Verou
The Misty Report - Douglas Crockford
Web performance optimisations for the harsh conditions - Anna Migas
Ad

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
Review of recent advances in non-invasive hemoglobin estimation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation

Lessons Learned from building Session Replay - Francesco Novy

  • 1. Session Replay Lessons Learned from Building a DOM capturing product Wey Wey Web 2023 Francesco Novy 1
  • 2. About Me Sentry & Session Replay How does Session Replay work? Lessons Learned: Know your Use Case Expect the Unexpected How to Optimize Bundle Size How to Compress Data Overview 2
  • 3. Francesco Novy hello@fnovy.com www.fnovy.com mydea Living in Vienna, Austria 8+ years of building web UIs At Sentry since 2022 Working on the JavaScript SDKs 3
  • 4. 4
  • 6. Capture what's happening in the user's browser See what happened leading up to an error In-depth debugging similar to the Browser DevTools Session Replay 6
  • 9. import * as Sentry from '@sentry/browser'; Sentry.init({ integrations: [ new Sentry.Replay({ unmask: ['.show-this-class'] }) ], // Always capture when an error happens replaysOnErrorSampleRate: 1.0, // Capture 10% of sessions generally replaysSessionSampleRate: 0.1, }); 1 2 3 4 5 6 7 8 9 10 11 12 13 How to use Session Replay? 9
  • 10. We use a fork of Mutation Observers Monkey Patching* Stylesheet APIs Monkey Patching* Canvas APIs rrweb How does it work? 10
  • 11. * What is Monkey Patching? const originalFetch = window.fetch; window.fetch = function() { console.log("A fetch happened!"); return originalFetch.apply(window, arguments); } // Later somewhere in the application window.fetch('https://example.com'); // Will show the console log 1 2 3 4 5 6 7 8 9 "Monkey patching is a technique used to dynamically update the behavior of a piece of code at run-time." 11
  • 12. Know your Use Case Expect the Unexpected How to Optimize Bundle Size How to Compress Data Lessons Learned 12
  • 13. Know your Use Case Do we really need that? 13
  • 14. Know your Use Case What do you really need? Hide text & user input by default Opt-in to show certain text Defaults matter: Make the best way the easy way Make the worst things impossible 14
  • 15. Expect the Unexpected Everything that can go wrong, will go wrong. 15
  • 16. Expect the Unexpected Low Level APIs are dangerous to tinker with Monkey Patching is dangerous Browser Extensions can do anything try-catch everything 16
  • 17. How to Optimize Bundle Size Ship as little code as necessary. 17
  • 18. Session Replay Bundle Size Bundle Size v7.73.0: ~53 KB Bundle Size v7.78.0: ~35 KB Still large 😱 ... but how? 18
  • 19. Optimizing Bundle Size Remove unused code from rrweb Audit dependencies Make certain recording features opt-in Optimize for Tree Shaking! 19
  • 20. What is Tree Shaking? describes the ability to automatically remove unused code from your build. When code is written in a tree-shakeable way, bundlers like Webpack can optimize your application based on what is actually used. Tree Shaking 20
  • 21. Tree Shaking: Simple Example // SDK import { large, small } from './my-code'; export function largeOrSmall(config) { return config.useLage ? large() : small(); } // Application import { largeOrSmall } from 'sdk'; largeOrSmall({ useLarge: false }); 1 2 3 4 5 6 7 8 9 10 11 ❌Not tree shakeable 21
  • 22. // SDK export { large, small } from './my-code'; // Application import { small } from 'sdk'; small(); 1 2 3 4 5 6 7 ✅Tree shakeable Tree Shaking: Simple Example 22
  • 23. // SDK import { CanvasManager } from './canvas-manager'; export function record(options) { if (options.recordCanvas) { new CanvasManager(); } } // Application import { record } from 'sdk'; record({ recordCanvas: false }); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ❌Not tree shakeable Tree Shaking: Actual Example 23
  • 24. // Application A import { record } from 'sdk'; record({ getCanvasManager: undefined }); 1 2 3 4 5 6 ✅Tree shakeable Tree Shaking: Actual Example // SDK import { CanvasManager } from './canvas-manager'; export function getCanvasManager() { return new CanvasManager(); } export function record(options) { if (options.getCanvasManager) { options.getCanvasManager(); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 // Application B import { record, getCanvasManager } from 'sdk'; record({ getCanvasManager }); 1 2 3 4 5 6 7 24
  • 25. How to Compress Data Avoid unnecessary network traffic, where possible. 25
  • 26. Compressing Data Compress data in a web worker Gracefully handle errors Make sure to compare libraries (e.g. ) fflate 26
  • 27. Web Workers Setting up the web worker // worker.js import { compressSync } from 'fflate'; function handleMessage(e) { const { input, id } = e.data; const compressed = compressSync(input); // Send compressed data back to main thread postMessage({ id, output: compressed }); } // Receive uncompressed data from main thread addEventListener('message', handleMessage); 1 2 3 4 5 6 7 8 9 10 11 12 27
  • 28. Web Workers Using the web worker from your application // Application const worker = new Worker('/worker.js'); function compressData(data) { const id = generateUuid(); return new Promise(function (resolve) { function listener(response) { if (response.data.id === id) { worker.removeEventListener('message', listener); resolve(response.data.output); } } worker.addEventListener('message', listener); worker.postMessage({ id, input: data }); }); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 28
  • 29. https://github.com/getsentry/sentry-javascript The Sentry SDK is Open Source! Everything we do is open source! Look at the code, PRs, etc. We love feedback! 29