Skip to content

Commit a5b9284

Browse files
authored
feat(replay): Change the behavior of error-based sampling (#7768)
* feat: Add `startBuffering()` API to begin replay buffering. This is useful if you turn off `replaysSessionSampleRate` and `replaysOnErrorSampleRate` and want to manually decide when to start replay buffering. You can then call `flush()` to save the replay. * fix: Sample at a per error rate instead of per session rate. Previously we were sampling at a per-session rather than per-error. This means the sampling decision happened prior to any error occurrence. The sampling rate was not accurate if you had sessions with many errors. This is now changed so that in the case of capturing replays only on error, we begin buffering the replay immediately and only run the sampling decision when an error occurs.
1 parent 1683caf commit a5b9284

File tree

31 files changed

+942
-173
lines changed

31 files changed

+942
-173
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window.Replay = new Sentry.Replay({
5+
flushMinDelay: 1000,
6+
flushMaxDelay: 1000,
7+
});
8+
9+
Sentry.init({
10+
dsn: 'https://[email protected]/1337',
11+
sampleRate: 1,
12+
replaysSessionSampleRate: 0.0,
13+
replaysOnErrorSampleRate: 0.0,
14+
15+
integrations: [window.Replay],
16+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
document.getElementById('go-background').addEventListener('click', () => {
2+
Object.defineProperty(document, 'hidden', { value: true, writable: true });
3+
const ev = document.createEvent('Event');
4+
ev.initEvent('visibilitychange');
5+
document.dispatchEvent(ev);
6+
});
7+
8+
document.getElementById('error').addEventListener('click', () => {
9+
throw new Error('Ooops');
10+
});
11+
12+
document.getElementById('error2').addEventListener('click', () => {
13+
throw new Error('Another error');
14+
});
15+
16+
document.getElementById('log').addEventListener('click', () => {
17+
console.log('Some message');
18+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button id="go-background">Go to background</button>
8+
<button id="error">Throw Error</button>
9+
<button id="error2">Another Error</button>
10+
<button id="log">Log stuff to the console</button>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)