Skip to content

feat(browser): Allow collecting of pageload profiles #9317

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 9 commits into from
Oct 24, 2023

Conversation

JonasBa
Copy link
Member

@JonasBa JonasBa commented Oct 19, 2023

Profiling is currently unable to profile page loads which creates a gap in the product as performance instrumentation seemingly can (via synthetic transactions)

In order to bridge this gap, the plan is to provide a small JS snippet that users can insert into their document which will initialize and store a reference to the pageload profile on the sentry carrier. By doing so we can hook back into our finishTransaction codepath and send a profile associated to a transaction.

Would love to hear early thoughts on this approach from SDK maintainers before I start adding test coverage.

@JonasBa JonasBa requested review from mydea, Lms24 and AbhiPrasad October 19, 2023 19:07
@JonasBa JonasBa force-pushed the jb/feat/pageload-profiling branch 3 times, most recently from 0e4d4bf to 330d1b1 Compare October 20, 2023 21:40
@JonasBa JonasBa force-pushed the jb/feat/pageload-profiling branch from 330d1b1 to c551f0a Compare October 20, 2023 21:40
@JonasBa
Copy link
Member Author

JonasBa commented Oct 22, 2023

I added a test to this and noticed that my current approach is not feasible because profiler.stop is async. Since transactions seem to be delegated to the transporter immediately after finish is called (correct me if I'm wrong, but this is what I observed when adding a test), it means the profiler promise will always resolve after the transaction is already sent, breaking the requirement for profiles and transactions to be sent in the same envelope.

As an alternative approach, I query for the current active transaction as soon as integration.setupOnce method is called and wrap it. The limitation of this approach is that if an intermediary transaction is created between pageload and our setupOnce method call which is active at the time of setupOnce call, we will no longer be able to wrap (as we may only query for the current active txn). There might be other situations where this might fail or better ways to approach this, I'm open to ideas.

For this to work reliably, we would need to be able to enumerate all of the active txns at time of integration setup so we can patch the finish step.

@JonasBa
Copy link
Member Author

JonasBa commented Oct 23, 2023

Revised implementation after meeting with the team (thanks @AbhiPrasad for the invite).

Instead of relying on the profile to already exist and its reference to be stored on the main carrier, start the profile as part of the BrowserProfilingIntegration.setupOnce call. This approach improves the default out of the box experience of browser profiling and browser tracing by enabling partial page load profiling for users who do not integrate a separate snippet to start the profiler before JS is loaded. This operates under the assumption that Sentry.init is one of the first things a user application should call, meaning there should be plenty of valuable main thread activity that follows which our profiler will be able to pick up.

A blind spot of this approach (and the reason why I'm calling it partial page load profiling) is that any JS activity happening between the document response and our SDK init will be missed. A solution to that would be to provide users with a snippet that would start the profile earlier (this can be done as a progressive enhancement at a later point).

I think this approach is much better than what I originally intended as it will provide an actual out-of-the-box experience for our users that doesn't require them to make any changes and is flexible enough so that it can be improved for more advanced users.

@AbhiPrasad AbhiPrasad requested a review from lforst October 23, 2023 18:49
@JonasBa
Copy link
Member Author

JonasBa commented Oct 23, 2023

@mydea @lforst @AbhiPrasad @Lms24 This is now ready for another review 🙏🏼

Copy link
Contributor

@lforst lforst left a comment

Choose a reason for hiding this comment

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

Minor things. Looks good!

@lforst lforst changed the title feat(browser): allow collecting of pageload profiles feat(browser): Allow collecting of pageload profiles Oct 24, 2023
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 82.66 KB (+0.18% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 71.77 KB (+0.16% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 30.94 KB (+0.95% 🔺)
@sentry/browser - Webpack (gzipped) 21.26 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 73.03 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.93 KB (+0.78% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 21.09 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 233.81 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 87.77 KB (+0.77% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 62.76 KB (+0.04% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.71 KB (+0.81% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 83.05 KB (+0.09% 🔺)
@sentry/react - Webpack (gzipped) 21.29 KB (+0.03% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 99.43 KB (+0.05% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 47.83 KB (+0.58% 🔺)

@AbhiPrasad
Copy link
Member

Let's get this merged, we can do another release with it in for tomorrow

@JonasBa
Copy link
Member Author

JonasBa commented Oct 24, 2023

@AbhiPrasad will merge this asap as CI passed. I also have a small fix that I will open for adjusting the timing of the pageload profiles as well.

@JonasBa JonasBa enabled auto-merge (squash) October 24, 2023 13:23
@JonasBa JonasBa merged commit 81c9651 into develop Oct 24, 2023
@JonasBa JonasBa deleted the jb/feat/pageload-profiling branch October 24, 2023 13:27
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.

3 participants