Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(replay): Change the behavior of error-based sampling #7768

Merged
merged 51 commits into from
Apr 26, 2023

Conversation

billyvg
Copy link
Member

@billyvg billyvg commented Apr 5, 2023

  • 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.

Closes #7735 #7744 #7193 #6537

`stop()` will now flush the eventBuffer before clearing it, as well as removing the session from Session Storage. Due to the flushing, `stop()` is now async.

Ref: #7738

this._addListeners();
const previousSessionId = this.session && this.session.id;

Check failure

Code scanning / CodeQL

Insecure randomness

This uses a cryptographically insecure random number generated at [Math.random()](1) in a security context.
packages/replay/src/replay.ts Outdated Show resolved Hide resolved
packages/replay/src/replay.ts Show resolved Hide resolved
packages/replay/src/replay.ts Outdated Show resolved Hide resolved
packages/replay/src/replay.ts Outdated Show resolved Hide resolved
packages/replay/src/replay.ts Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.03 KB (+0.01% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 65.66 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.56 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 58.12 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 21.17 KB (0%)
@sentry/browser - Webpack (minified) 69.07 KB (0%)
@sentry/react - Webpack (gzipped + minified) 21.19 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.03 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.59 KB (0%)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.82 KB (+0.01% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 46.81 KB (+0.54% 🔺)
@sentry/replay - Webpack (gzipped + minified) 40.59 KB (+0.57% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 65.62 KB (+0.43% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 58.57 KB (+0.42% 🔺)

@billyvg billyvg changed the base branch from develop to feat-replay-change-stop-flush-clear-session April 13, 2023 20:45
@billyvg billyvg force-pushed the feat-replay-change-sampling-logic branch from 1e7f0eb to 1412dec Compare April 13, 2023 20:46
@billyvg billyvg force-pushed the feat-replay-change-sampling-logic branch from 128338f to e954fe0 Compare April 14, 2023 21:45
@billyvg billyvg marked this pull request as ready for review April 18, 2023 20:55
@billyvg billyvg requested a review from mydea April 18, 2023 20:55
@billyvg billyvg force-pushed the feat-replay-change-sampling-logic branch from ca4d679 to de5607d Compare April 24, 2023 14:07
@@ -36,8 +36,9 @@ export function getSession({

if (!isExpired) {
return { type: 'saved', session };
} else if (session.sampled === 'error') {
// Error samples should not be re-created when expired, but instead we stop when the replay is done
} else if (!session.shouldRefresh) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing, just to make this sure and clear, is that this means that when an error session expires without an error happened, it could be re-started as a session-session, right? So we may sample it and start sending data once the session resumes. IMHO that's OK, just wanting to be explicit in behavior!

packages/replay/src/types.ts Outdated Show resolved Hide resolved
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change! Left a few comments but all very low importance, just small nitpicks. Looking great 🚀

Base automatically changed from feat-replay-change-stop-flush-clear-session to develop April 26, 2023 08:54
throw new Error('Replay recording is already in progress');
}

const previousSessionId = this.session && this.session.id;

Check failure

Code scanning / CodeQL

Insecure randomness

This uses a cryptographically insecure random number generated at [Math.random()](1) in a security context.
@billyvg billyvg force-pushed the feat-replay-change-sampling-logic branch from 97cd546 to d7554b8 Compare April 26, 2023 11:08
@billyvg billyvg enabled auto-merge (squash) April 26, 2023 11:45
@billyvg billyvg merged commit a5b9284 into develop Apr 26, 2023
@billyvg billyvg deleted the feat-replay-change-sampling-logic branch April 26, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change Replay sampling to sample on each error
2 participants