-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: Stop passing defaultIntegrations
as client option
#15307
base: develop
Are you sure you want to change the base?
Conversation
size-limit report 📦
|
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
@@ -59,27 +58,10 @@ export function applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOpt | |||
|
|||
return { | |||
...defaultOptions, | |||
...dropTopLevelUndefinedKeys(optionsArg), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be necessary anymore with this change!
08ca723
to
9d11a83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial impression: I think this is a good change and I'm looking forward to seeing the Integration[]
being removed from defaultIntegrations
. This should rease a potential footgun from the API surface.
I think the initWithDefaultIntegrations
pattern is fine and if we can reduce bundle size with it (as in the Angular case), it justifies the added API surface.
checkAndSetAngularVersion(); | ||
return browserInit(opts); | ||
|
||
return initWithDefaultIntegrations(opts, getDefaultIntegrations); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that I see this: is it even correct to call checkAndSetAngularVersion
before initWithDefaultIntegrations
(or formerly browserInit
)? Given that this calls setContext
before the actual client exists...
I guess it somehow works but probably it's better to first call init, then checkSetNgVersion and then return the client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fine because the scope remains valid even before the client is created (one of the particular design goals we considered with the current scope stuff 😅 )
/** | ||
* Initialize a browser client with the provided options and default integrations getter function. | ||
*/ | ||
export function initWithDefaultIntegrations( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: can we add a test or two for this function?
* It is deprecated to pass `Integrations[]` here. This capability will be removed in v10. | ||
* | ||
* TODO(v10): Remove `Integration[]` support. | ||
*/ | ||
defaultIntegrations?: false | Integration[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: not sure if you already tried this but if we split up the type and union-type it again, can we somehow add @deprecated
to the Integration[] type? might not work, so feel free to disregard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a few ways but could not get it to work 😬 if we do e.g. this:
/** @deprecated oh no */
type DeprecatedStuff = Integration[];
// ...
interface {
defaultIntegrations: false | DeprecatedStuff;
}
then it complains in there that this is deprecated (so we need to add an eslint-disable comment), but for users its fine to pass this 😬
packages/core/src/integration.ts
Outdated
// TODO(v10): If an array is passed, we use this - this is deprecated and will eventually be removed | ||
// Else, we use the default integrations that are directly passed to this function as second argument | ||
const defaultIntegrationsToUse = | ||
options.defaultIntegrations === false | ||
? [] | ||
: Array.isArray(options.defaultIntegrations) | ||
? options.defaultIntegrations | ||
: defaultIntegrations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: If we can't get my suggestion with deprecated
to work, wdyt about adding a log here that passing an array will be removed in v10? Again, no super strong feelings but I'm fairly sure that people (mis-)use this option quite a lot which is why I'm thinking it's worth thinking about this.
packages/browser/src/sdk.ts
Outdated
/** | ||
* Initialize a browser client with the provided options and default integrations getter function. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Based on your PR description:
/** | |
* Initialize a browser client with the provided options and default integrations getter function. | |
*/ | |
/** | |
* Initialize a browser client with the provided options and default integrations getter function. | |
* | |
* @hidden | |
* @internal - This is only intended for internal use. Use at your own risk! | |
*/ |
9d11a83
to
e507097
Compare
I added tests here, should be good to go! |
This PR updates the handling of
defaultIntegrations
to avoid our own SDKs ever setting this option. Instead, we manually do this and expose a newinitWithDefaultIntegrations
method which is designed for internal use. We already have something similar (which in that case is replaced by the new method) in node, to allow tree shaking of integrations for serverless SDKs.Status Quo
Today, the way we handle default integrations is a bit non-ideal:
We have an option called
defaultIntegrations
which users can set tofalse
to opt out of any default integrations.However, that property also allows to pass
Integrations[]
, which is not really something we want any user to do (just setdefaultIntegrations: false
and passintegrations: [...]
if you want to do this), but more something that we use internally in the SDKs. However, this leads to a bit of an overloaded behavior there.Especially, because we allow users to overwrite this, but need to differentiate if this has been inherited by an upstream SDK. This is because e.g. the next SDK (and many others) does this:
This is actually technically false, because if a user does this:
init({ defaultIntegrations: undefined })
this will result in no default integrations being set, instead of using the default ones.We have partially fixed this in some places by specifically checking for
undefined
there etc, but overall this is just not an ideal design.Additionally, it also has the problem that you cannot tree shake default integrations of upstream SDKs. E.g. the angular SDK has its own set of default integrations, skipping
BrowserApiErrors
. However, with the current design, that integration is still included in the bundle.New behavior in this SDK
For example, this is the old vs new behavior:
In the places where an actual client is constructed, we pass these in directly now, like this:
And this function, in turn, can now properly check the passed in user options, ensuring they have precedence, and use the SDK defaultIntegrations where appropriate.
Note:
initWithDefaultIntegrations
accepts a getter method instead of just taking the array of integrations, because in some cases we build default integrations based on options, and we want to have the fully built options there with all defaults etc. applied, so that this is definitely correct. It has the additional benefit that it is easier to tree shake.Related to #14950