Skip to content

ref(replay): Make Session a POJO #6417

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

Merged
merged 7 commits into from
Dec 6, 2022
Merged

ref(replay): Make Session a POJO #6417

merged 7 commits into from
Dec 6, 2022

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 5, 2022

While the replay session was made a class here: getsentry/sentry-replay#91, since we landed #6315, it's not really necessary anymore to have this be a class.

This PR refactors this to a simple POJO with a function to easily generate it with defaults etc.
Also, some things like the toJSON() where only used in tests. We should generally avoid this, and instead provide some test utils specifically for these things (where necessary), to avoid shipping this to our end users.

@mydea mydea added the Package: replay Issues related to the Sentry Replay SDK label Dec 5, 2022
@mydea mydea requested review from billyvg and Lms24 December 5, 2022 16:23
@mydea mydea self-assigned this Dec 5, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.6 KB (-0.01% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 60.69 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.37 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 54.26 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.13 KB (0%)
@sentry/browser - Webpack (minified) 65.83 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.16 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.01 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.44 KB (-0.01% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.87 KB (+0.02% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 41.81 KB (-0.21% 🔽)
@sentry/replay - Webpack (gzipped + minified) 37.32 KB (-0.23% 🔽)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Nice!

@Lms24
Copy link
Member

Lms24 commented Dec 5, 2022

Eventually, we'd like to get rid of nullish coalescencing operators to save some bundle size but we can tackle this when we get to bundle size optimization later on as well.

@mydea
Copy link
Member Author

mydea commented Dec 5, 2022

Eventually, we'd like to get rid of nullish coalescencing operators to save some bundle size but we can tackle this when we get to bundle size optimization later on as well.

Good point, I'll implement that as well while I'm at it! Check it out.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Awesome! Feels like v7 work all over again, we right back to it!

/**
* Get a session with defaults & applied sampling.
*/
export function makeSession(session: Partial<Session>, { sessionSampleRate, errorSampleRate }: SampleRates): Session {
Copy link
Member

Choose a reason for hiding this comment

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

nit: If we get rid of the obj arg in favour of direct args with sessionSampleRate and errorSampleRate we'll save some bytes because we can minify those variables.

This makes sense to do if makeSession is not user facing, as then we can change the method signature in the future.

@mydea
Copy link
Member Author

mydea commented Dec 6, 2022

So I adjusted this a bit based on feedback from @AbhiPrasad . basically, I extracted the sampling decision out into a dedicated function, that only needs to be called when creating a new session. No need to actually call this in fetchSession, as there the session has to have sampled already. This allowed to slightly reduce bundle size.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

LGTM. I like the sampled change

@mydea mydea force-pushed the fn/replay-session-pojo branch from 430e6fe to a0c0afd Compare December 6, 2022 11:03
@mydea mydea merged commit 22206e3 into master Dec 6, 2022
@mydea mydea deleted the fn/replay-session-pojo branch December 6, 2022 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants