fix(nextjs): Allow onUncaughtException
integration to remain excluded
#6148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the nextjs SDK, the
addOrUpdateIntegration
function exists to force the inclusion of certain integrations with certain options set. If such an integration is included in the underlying SDK's default integrations, however, (in other words, if it's included in the defaults set by@sentry/browser
or@sentry/node
), it's possible for the user to have actively chosen to exclude it, which we would then be overriding. This PR adds to theaddOrUpdateIntegration
logic to provide the ability to respect that choice.The only way for a user to choose to filter out a default integration is by providing a function as their
integrations
option inSentry.init()
. Therefore, when handling the function case, we can check if a given integration is included in the return value, and if it's not, not add the default instance we otherwise would. This is controlled by a flag on that default instance namedallowExclusionByUser
. If it's set totrue
, we'll perform the check and respect the user's choice. If it's set tofalse
or not set at all, we'll continue to behave as we have, forcing the inclusion of the given integration.The inspiration for this change is our recent inclusion of the
onUncaughtException
integration in the nextjs defaults. This PR therefore also applies the above change to that default instance.Finally, the test suite for
addOrUpdateIntegration
has been entirely reworked, to ensure that it covers all possible cases.Supersedes #6142.