-
-
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(nuxt): Expose vueIntegration
#14526
Merged
+69
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { GLOBAL_OBJ, defineIntegration } from '@sentry/core'; | ||
import type { VueIntegrationOptions } from '@sentry/vue'; | ||
|
||
type Options = Omit< | ||
VueIntegrationOptions, | ||
| 'app' | ||
| 'Vue' | ||
// TODO(v9): Should be removed from parent type so we can remove it here | ||
| 'hooks' | ||
// TODO(v9): Should be removed from parent type so we can remove it here | ||
| 'timeout' | ||
// TODO(v9): Should be removed from parent type so we can remove it here | ||
| 'trackComponents' | ||
>; | ||
|
||
// Since the options object needs to cross the boundary between some builds (i.e. the nuxt module build and our client | ||
// SDK build) we cannot use a getter that is exported from here. Instead we'll pass the options object through a global | ||
// to the module. | ||
export type GlobalObjWithIntegrationOptions = { _sentryNuxtVueIntegrationOptions?: Options }; | ||
|
||
// The vue integration is actually set up in the Sentry Client Module. There it is set up as soon as the nuxt app object is available. | ||
// However, we need to export the vueIntegration from the Client SDK. This means all this integration does is store away | ||
// its options for the Sentry Client Module to pick them up when initializing the actual vueIntegration. | ||
|
||
/** | ||
* Add additional error and span instrumentation specialized for Vue. | ||
*/ | ||
export const vueIntegration = defineIntegration((options: Options = {}) => { | ||
return { | ||
// NOTE: This name is different from the original vueIntegration's name. | ||
name: 'NuxtVueIntegration', | ||
setup() { | ||
(GLOBAL_OBJ as GlobalObjWithIntegrationOptions)._sentryNuxtVueIntegrationOptions = options; | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Just a question: If users add a
vueIntegration
as well, can this even be another another time? I remember it's not possible to add the same integration twice.What we could do is removing this
addIntegration
part here and add thevueIntegration
as default integration in the default integration array (users can overwrite those integrations). As we need to get thevueApp
in the integration, we can get it fromwindow.useNuxtApp().vueApp
.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.
The reason why I immediately went with this solution is because I thought the
vueApp
is initialized rather late - at least later thanSentry.init()
is called. In that case, we would initialize the SDK (and call the integrations' setup method) beforewindow.useNuxtApp()
is even available. Is my concern valid? I think you know more than me in this regard.I don't think I fully understand this question. Can you clarify a bit?
How this PR is currently implemented, the configuration added by the user would "win" and their options are used when we add the
vueIntegration()
in the nuxt pluginsetup
hook.The entire point of this PR is that users can add their own
vueIntegration()
. Maybe I am also misunderstanding. In case you are worried about "us adding the integration twice", that is actually not the case in this PR - the name between the@sentry/nuxt
vueIntegration()
and the@sentry/vue
integration differs slightly, so they will both be set up.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.
In the client-case, the Nuxt app is initialized before Sentry. I haven't tried so far but it should work in theory.
True, I wasn't thinking about that...those are two different integrations and not the same. And the new Nuxt
vueIntegration
is only setting the options, the logic is inside VuevueIntegration
which will still be added but with the added options? I understood it now :DAll good - I should have read the comment in the integration