Skip to content

feat(utils): Introduce getGlobalSingleton helper #4860

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 2 commits into from
Apr 6, 2022

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Apr 5, 2022

This helper abstracts away the logic of getting an variable from the global __SENTRY__ object. It does this by introducing a new getGlobalSingleton utility function.

For now, this is used by the event processors and hub logic. In an upcoming PR, we'll update the logger logic to also use this utility.

Based on the excellent work in #4285 - should be a small bundle size win as well. Well ok size-bot, say no more.

Resolves https://getsentry.atlassian.net/browse/WEB-796

This helper abstracts away the logic of getting an variable from the
global `__SENTRY__` object. It does this by introducing a new
`getGlobalSingleton` utility function.

For now, this is used by the event processors and hub logic. In an
upcoming patch, we'll update the logger logic to also use this utility.
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 20.24 KB (+0.15% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 65.17 KB (-0.14% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.89 KB (+0.03% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 58.15 KB (-0.21% 🔽)
@sentry/browser - Webpack (gzipped + minified) 23.25 KB (+0.1% 🔺)
@sentry/browser - Webpack (minified) 82.13 KB (-0.06% 🔽)
@sentry/react - Webpack (gzipped + minified) 23.29 KB (+0.1% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 48.06 KB (+0.08% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.18 KB (+0.1% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.53 KB (+0.09% 🔺)

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

Good change!

@@ -631,7 +636,7 @@ export function getHubFromCarrier(carrier: Carrier): Hub {
*/
export function setHubOnCarrier(carrier: Carrier, hub: Hub): boolean {
if (!carrier) return false;
carrier.__SENTRY__ = carrier.__SENTRY__ || {};
carrier.__SENTRY__.hub = hub;
const sentry = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const sentry = (carrier.__SENTRY__ = carrier.__SENTRY__ || {});
const sentry = carrier.__SENTRY__ = carrier.__SENTRY__ || {};

Will prettier let you do this without ()? If so, I think it's easier to read without them.

Also, what do you think of calling this variable __SENTRY__, since that's what it is?

Copy link
Member Author

Choose a reason for hiding this comment

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

switched to variable __SENTRY__, can't make the () change because of prettier.

Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

LGTM!

@AbhiPrasad AbhiPrasad added this to the Pre 7.0.0 Work milestone Apr 6, 2022
@AbhiPrasad AbhiPrasad merged commit eb11979 into master Apr 6, 2022
@AbhiPrasad AbhiPrasad deleted the abhi-get-global-singleton branch April 6, 2022 02:19
@zeckdude
Copy link

@AbhiPrasad I'm getting this error when I follow the directions at https://docs.sentry.io/platforms/javascript/guides/nextjs/#install and I think it's related to what you did here:

unhandledRejection: TypeError: utils.getGlobalSingleton is not a function

Do you have any ideas how I can make this error go away?

@AbhiPrasad
Copy link
Member Author

Hey @zeckdude to help us take a look, could you open a GitHub issue with:

  1. the list of steps you followed to install
  2. the output of npm ls @sentry/utils and npm ls @sentry/nextjs
  3. what version of the SDK you are installing
  4. Details about your environment - using npm/yarn/pnpm, versions etc.

On the latest version, this function should be existing and properly exported. See it on the unpkg CDN here: https://unpkg.com/browse/@sentry/[email protected]/esm/global.js

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