Skip to content
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
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Idk man is this better?
  • Loading branch information
lforst committed Nov 29, 2024
commit a061e6917eb3d767cd3ee1ed8a3699c045b334c5
24 changes: 13 additions & 11 deletions packages/nuxt/src/client/vueIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineIntegration } from '@sentry/core';
import { GLOBAL_OBJ, defineIntegration } from '@sentry/core';
import type { VueIntegrationOptions } from '@sentry/vue';

type Options = Omit<
Expand All @@ -13,19 +13,21 @@ type Options = Omit<
| 'trackComponents'
>;

let nuxtVueIntegrationOptions: Options | undefined;
// 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 = {}) => {
nuxtVueIntegrationOptions = options;
(GLOBAL_OBJ as GlobalObjWithIntegrationOptions)._sentryNuxtVueIntegrationOptions = options;
return {
name: 'NuxtVueIntegration',
};
});

/**
* The vueIntegration exported by the Nuxt SDK does nothing besides storing it's options to the side so we can later pick them up when we add the actual vueIntegration.
* This function allows us to pick up the options.
*/
export function retrieveNuxtVueIntegrationOptions(): Options | undefined {
return nuxtVueIntegrationOptions;
}
7 changes: 4 additions & 3 deletions packages/nuxt/src/runtime/plugins/sentry.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getClient } from '@sentry/core';
import { GLOBAL_OBJ, getClient } from '@sentry/core';
import { browserTracingIntegration, vueIntegration } from '@sentry/vue';
import { defineNuxtPlugin } from 'nuxt/app';
import { retrieveNuxtVueIntegrationOptions } from '../../client/vueIntegration';
import type { GlobalObjWithIntegrationOptions } from '../../client/vueIntegration';
import { reportNuxtError } from '../utils';

// --- Types are copied from @sentry/vue (so it does not need to be exported) ---
Expand Down Expand Up @@ -56,7 +56,8 @@ export default defineNuxtPlugin({
// We don't want to wrap the existing error handler, as it leads to a 500 error: https://github.com/getsentry/sentry-javascript/issues/12515
sentryClient.addIntegration(
vueIntegration({
...retrieveNuxtVueIntegrationOptions(),
// We pick up the options from the "fake" vueIntegration exported by the SDK.
...(GLOBAL_OBJ as GlobalObjWithIntegrationOptions)._sentryNuxtVueIntegrationOptions,
app: vueApp,
attachErrorHandler: false,
}),
Expand Down
Loading