-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(nextjs): Simplify adding default integrations when initializing SDK #5702
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
ref(nextjs): Simplify adding default integrations when initializing SDK #5702
Conversation
size-limit report 📦
|
0bd5df0
to
5b65fff
Compare
return [defaultBrowserTracingIntegration]; | ||
} | ||
return addOrUpdateIntegration(defaultBrowserTracingIntegration, userIntegrations, { | ||
'options.routingInstrumentation': nextRouterInstrumentation, |
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.
With this API, couldn't we collide if integrations have the same option name?
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.
It's the same API as before, just a slightly simpler implementation - it still filters on integration name. See the const userInstance = userIntegrations.find(integration => integration.name === defaultIntegrationInstance.name);
line in addOrUpdateIntegrationInArray
.
What it doesn't protect against is duplicates (the way the main integration logic does), but hopefully users won't be giving us two copies of the same integration.
3fb85ca
to
4a9c167
Compare
4a9c167
to
0414730
Compare
While working on adding a
RequestData
integration to the nextjs SDK, I found that the functions we use to set default integrations in the SDK were a little hard to parse, primarily because of a docstring that didn't make any sense and vague and/or slightly inaccurate function and variable names. We also have been making things more complicated than necessary, in thata) The existing functions in
utils/userIntegrations.ts
use the given default integration instance if no user instance is found. Meanwhile, the two index files do the same in the case that no user integrations are provided at all. But those two conditions aren't logically independent, so by simply providing a default (empty) value for the second case, we can rely on the first check to ensure the default instance is used. (See the now-removedif (options.integrations)
check in both of the index files.)b) The options we want to force onto any user instance we find have been living in a nested object which really doesn’t need to be nested. (See the
Options
- nowForcedIntegrationOptions
- type inutils/userIntegrations.ts
.)c) We've essentially been manually implementing
Array.find
, which there's no reason for us to do. (See thefor
-loop inaddIntegrationToArray
- nowaddOrUpdateIntegrationInArray
- inutils/userIntegrations.ts
.)This fixes those problems, rewrites the docstring, and renames a bunch of variables. It also
integrations
array when testing an individual integration type.setNestedKey
.For ease of reviewing, the docstring/renaming changes have been separated into a separate commit from the logic changes, test reorg, and bugfix.