Skip to content

feat: Refactor exposed defaultIntegrations to getDefaultIntegrations() #10243

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 1 commit into from
Jan 19, 2024

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 18, 2024

The current implementation has two problems:

  1. It is weird that you can accidentally mutate the default integrations of another package
  2. We sometimes have logic-based default integrations - e.g. adding an integration only if tracing is enabled, or similar. This means that either we have to add some logic in the upstream SDK to ensure this is still added even if downstream SDKs overwrite default integrations, or we need to duplicate the logic in the downstream SDKs. With this new method, we can instead centralize this, and downstream SDKs simply need to call upstream getDefaultIntegrations(options).

@mydea mydea requested review from lforst, Lms24 and AbhiPrasad January 18, 2024 13:47
@mydea mydea self-assigned this Jan 18, 2024
@mydea mydea force-pushed the fn/getDefaultIntegrations branch from b3912df to c630aba Compare January 18, 2024 13:47
Copy link
Contributor

github-actions bot commented Jan 18, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77.62 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.88 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 72.77 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.52 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.89 KB (+0.01% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.16 KB (+0.01% 🔺)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.16 KB (+0.01% 🔺)
@sentry/browser - Webpack (gzipped) 22.51 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 75.21 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 66.83 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 32.68 KB (+0.07% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.23 KB (+0.09% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 210.56 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 98.54 KB (+0.06% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 72.52 KB (+0.08% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 35.73 KB (+0.07% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 69.3 KB (+0.01% 🔺)
@sentry/react - Webpack (gzipped) 22.55 KB (+0.02% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.88 KB (+0.01% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 50.01 KB (+0.01% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.14 KB (0%)

/** Get the default integrations for the browser SDK. */
export function getDefaultIntegrations(_options: Options): Integration[] {
// eslint-disable-next-line deprecation/deprecation
return defaultIntegrations.slice();
Copy link
Member

@Lms24 Lms24 Jan 18, 2024

Choose a reason for hiding this comment

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

are we slicing here to return a copy of defaultIntegrations? I'm fine with that (I guess it doesn't matter if we do that or [...defaultIntegrations]), but we might wanna add a comment for clarity because it looks like a no-op. I think we do it to avoid mutation of the original array, correct?

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 the same as [...defaultIntegrations] - not sure if there is a perf difference or so there!

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with slice, just think we should add a comment

…ns()`

The current implementation has some problems:

1. It is weird that you can accidentally mutate the default integrations of another package
2. We sometimes have logic-based default integrations - e.g. adding an integration only if tracing is enabled, or similar. This means that either we have to add some logic in the _upstream_ SDK to ensure this is still added even if downstream SDKs overwrite default integrations, or we need to duplicate the logic in the _downstream_ SDKs. With this new method, we can instead centralize this, and downstream SDKs simply need to call upstream `getDefaultIntegrations(options)`.
@mydea mydea force-pushed the fn/getDefaultIntegrations branch from 90b4a20 to e227076 Compare January 19, 2024 08:19
@mydea mydea merged commit 33d1cb0 into develop Jan 19, 2024
@mydea mydea deleted the fn/getDefaultIntegrations branch January 19, 2024 08:39
mydea added a commit that referenced this pull request Jan 19, 2024
We should wait for
#10243 to merge this,
as otherwise we'll get a deprecation/eslint error there.
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.

2 participants