Skip to content

Commit

Permalink
feat(replay): Change the behavior of error-based sampling (#7768)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
billyvg authored Apr 26, 2023
1 parent 1683caf commit a5b9284
Show file tree
Hide file tree
Showing 31 changed files with 942 additions and 173 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window.Replay = new Sentry.Replay({
flushMinDelay: 1000,
flushMaxDelay: 1000,
});

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
sampleRate: 1,
replaysSessionSampleRate: 0.0,
replaysOnErrorSampleRate: 0.0,

integrations: [window.Replay],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
document.getElementById('go-background').addEventListener('click', () => {
Object.defineProperty(document, 'hidden', { value: true, writable: true });
const ev = document.createEvent('Event');
ev.initEvent('visibilitychange');
document.dispatchEvent(ev);
});

document.getElementById('error').addEventListener('click', () => {
throw new Error('Ooops');
});

document.getElementById('error2').addEventListener('click', () => {
throw new Error('Another error');
});

document.getElementById('log').addEventListener('click', () => {
console.log('Some message');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<button id="go-background">Go to background</button>
<button id="error">Throw Error</button>
<button id="error2">Another Error</button>
<button id="log">Log stuff to the console</button>
</body>
</html>
Loading

0 comments on commit a5b9284

Please sign in to comment.