Skip to content

ref(replay): Extract some functions out from class #6448

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 15 commits into from
Dec 9, 2022

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 7, 2022

This is a first pass of extracting some functions out from the core replay class into functions.
There is for sure much more refactoring potential there, for now mostly we pass replay into the class as arguments, eventually we can def. make this more atomic. But it should be a starting point. There are also more functions to extract, but I figured we can do this in waves.

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

github-actions bot commented Dec 7, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.67 KB (-0.01% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 60.94 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.46 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 54.49 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.26 KB (0%)
@sentry/browser - Webpack (minified) 66.24 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.29 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.28 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.66 KB (-0.01% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.11 KB (+0.01% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 41.75 KB (-0.1% 🔽)
@sentry/replay - Webpack (gzipped + minified) 37.85 KB (-0.15% 🔽)

@mydea mydea force-pushed the fn/replay-extract-fn-1 branch 2 times, most recently from 6294803 to 54c3a1d Compare December 7, 2022 09:21
// Do not apply replayId to the root event
if (
// @ts-ignore new event type
event.type === REPLAY_EVENT_NAME
Copy link
Member

Choose a reason for hiding this comment

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

m: can we create a issue or add a todo somewhere that adds this event type to the TS types?

Also @JonasBa do we need to do the same for profiling?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is planned as next step - need to write up an issue!

Comment on lines +32 to +38
replay.getContext().traceIds.add(event.contexts.trace.trace_id as string);
return event;
}

// no event type means error
if (!event.type) {
replay.getContext().errorIds.add(event.event_id as string);
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to add methods to replay to so that we don't expose the data structure/context here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I would like to keep refining the public API surface of this over time. there are a few more places where IMHO we can/should tighten this up! I'll leave this as is for now, but note down to revisit this!

}

// Need to collect visited URLs
replay.getContext().urls.push(result.name);
Copy link
Member

Choose a reason for hiding this comment

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

Similar thing to above with trace/error ids.

@mydea mydea force-pushed the fn/replay-extract-fn-1 branch from 78a9df4 to 12840da Compare December 7, 2022 14:12
* Create a "span" for the total amount of memory being used by JS objects
* (including v8 internal objects).
*/
export function addMemoryEntry(replay: ReplayContainer): Promise<void[]> | undefined {
Copy link
Member

Choose a reason for hiding this comment

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

l: can we change the func signature here to just be void? Then we don't need the return statements and we can also just void createPerformanceSpans

Copy link
Member Author

Choose a reason for hiding this comment

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

good finding, there is actually nothing async about this 😅 so should be good to clean up. done!

Copy link
Member

Choose a reason for hiding this comment

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

addEvent should be async

Copy link
Member Author

Choose a reason for hiding this comment

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

addEvent was also sync before, and we are not really waiting for it anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

🤔 , it may have been a bug -- eventbuffer's addevent is async, looks like replay.addEvent was not returning the promise.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I think you're right - but I'll make a separate PR to fix that 👍

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.

With some further refactoring in mind, let's :shipit:

@mydea mydea force-pushed the fn/replay-extract-fn-1 branch from 26840af to cf54a67 Compare December 9, 2022 09:35
@mydea mydea merged commit 65245f4 into master Dec 9, 2022
@mydea mydea deleted the fn/replay-extract-fn-1 branch December 9, 2022 10:20
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