Skip to content

feat(core): Remove getCurrentHub from AsyncContextStrategy #11581

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

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Apr 12, 2024

This PR removes the getCurrentHub property from the AsyncContextStrategy interface and consequently also the property in the interface implementers.

There's still some stuff left to clean up but it is only internal anymore.

Hopefully the last breaking change in connection to #11482

Copy link
Contributor

github-actions bot commented Apr 12, 2024

size-limit report 📦

Path Size
@sentry/browser 22.16 KB (-0.07% 🔽)
@sentry/browser (incl. Tracing) 31.75 KB (-0.04% 🔽)
@sentry/browser (incl. Tracing, Replay) 67.07 KB (-0.03% 🔽)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 60.48 KB (-0.02% 🔽)
@sentry/browser (incl. Tracing, Replay with Canvas) 70.9 KB (-0.03% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback) 80.8 KB (-0.02% 🔽)
@sentry/browser (incl. Feedback) 35.71 KB (-0.04% 🔽)
@sentry/browser (incl. Feedback, Feedback Modal) 35.71 KB (-0.04% 🔽)
@sentry/browser (incl. Feedback, Feedback Modal, Feedback Screenshot) 37.74 KB (-0.04% 🔽)
@sentry/browser (incl. sendFeedback) 26.95 KB (-0.06% 🔽)
@sentry/react 24.84 KB (-0.06% 🔽)
@sentry/react (incl. Tracing) 34.65 KB (-0.06% 🔽)
@sentry/vue 25.73 KB (-0.07% 🔽)
@sentry/vue (incl. Tracing) 33.47 KB (-0.05% 🔽)
@sentry/svelte 22.29 KB (-0.07% 🔽)
CDN Bundle 24.48 KB (+0.76% 🔺)
CDN Bundle (incl. Tracing) 32.98 KB (+0.58% 🔺)
CDN Bundle (incl. Tracing, Replay) 66.6 KB (+0.25% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) 82.81 KB (+0.25% 🔺)
CDN Bundle - uncompressed 72.9 KB (+0.74% 🔺)
CDN Bundle (incl. Tracing) - uncompressed 98.95 KB (+0.54% 🔺)
CDN Bundle (incl. Tracing, Replay) - uncompressed 208.61 KB (+0.26% 🔺)
@sentry/nextjs (client) 34.02 KB (-0.05% 🔽)
@sentry/sveltekit (client) 32.26 KB (-0.05% 🔽)
@sentry/node 120.09 KB (-0.2% 🔽)

Comment on lines -509 to -515
export function getCurrentHub(): HubInterface {
// Get main carrier (global for every environment)
const carrier = getMainCarrier();

const acs = getAsyncContextStrategy(carrier);
return acs.getCurrentHub() || getGlobalHub();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

It's no longer necessary to read from the carrier here since acs doesn't have the getCurrentHub method anymore. This means that we can replace this entire implementation with the shim which in turn will again forward its respective calls to the globalHub (to be renamed).

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to remove getGlobalHub usage and make everything rely on the shim, though that does mean we need to refactor more of the return values in getHubStackAsyncContextStrategy

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 talked about this with @mydea and that's basically what we should do. getHubStackAsyncContextStrategy has to stay in one way or the other since our fallback (i.e. browser) async context strategy is still a stack-based scope hierarchy. getGlobalHub currently returns a Hub class instance which we can probably cut down a lot to only handle the scope stack. At this point we can then also rename this to something like globalScopeStackAsyncContextStrategy.

@Lms24 Lms24 requested a review from mydea April 12, 2024 13:56
@Lms24 Lms24 self-assigned this Apr 12, 2024
@Lms24
Copy link
Member Author

Lms24 commented Apr 12, 2024

oh god I just opened a whole box of circular dependency problems - these are not fun to resolve 😅

update: nvm, the circular dep was caused by me importing getCurrentHubShim into hub.ts and I fixed it by just moving getCurrentHub to the shim file. This is fine for now but something still feels off with our import chain in core. I think the convoluted exports.ts and hub.ts are quite likely to cause us some headaches in the future.

@Lms24 Lms24 force-pushed the lms/feat-core-remove-asyncContextStrategy-getCurrentHub branch from 4e91097 to b0ae26d Compare April 12, 2024 15:27
@Lms24 Lms24 force-pushed the lms/feat-core-remove-asyncContextStrategy-getCurrentHub branch from 21ff82b to e658aff Compare April 12, 2024 15:44
Copy link
Member Author

Choose a reason for hiding this comment

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

The imports in this file caused a (rather unrelated but still existing) circular dependency in the core package.

@Lms24 Lms24 merged commit 409624b into develop Apr 15, 2024
@Lms24 Lms24 deleted the lms/feat-core-remove-asyncContextStrategy-getCurrentHub branch April 15, 2024 09:42
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