Skip to content

Commit 6044278

Browse files
author
Luca Forstner
committed
feat(nuxt): Expose vueIntegration
1 parent cfb68ca commit 6044278

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

packages/nuxt/src/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from '@sentry/vue';
22

33
export { init } from './sdk';
44
export { piniaIntegration } from './piniaIntegration';
5+
export { vueIntegration } from './vueIntegration';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { defineIntegration } from '@sentry/core';
2+
import type { VueIntegrationOptions } from '@sentry/vue';
3+
4+
type Options = Omit<
5+
VueIntegrationOptions,
6+
| 'app'
7+
| 'Vue'
8+
// TODO(v9): Should be removed from parent type so we can remove it here
9+
| 'hooks'
10+
// TODO(v9): Should be removed from parent type so we can remove it here
11+
| 'timeout'
12+
// TODO(v9): Should be removed from parent type so we can remove it here
13+
| 'trackComponents'
14+
>;
15+
16+
let nuxtVueIntegrationOptions: Options | undefined;
17+
18+
export const vueIntegration = defineIntegration((options: Options = {}) => {
19+
nuxtVueIntegrationOptions = options;
20+
return {
21+
name: 'NuxtVueIntegration',
22+
};
23+
});
24+
25+
/**
26+
* 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.
27+
* This function allows us to pick up the options.
28+
*/
29+
export function retrieveNuxtVueIntegrationOptions(): Options | undefined {
30+
return nuxtVueIntegrationOptions;
31+
}

packages/nuxt/src/runtime/plugins/sentry.client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getClient } from '@sentry/core';
22
import { browserTracingIntegration, vueIntegration } from '@sentry/vue';
33
import { defineNuxtPlugin } from 'nuxt/app';
4+
import { retrieveNuxtVueIntegrationOptions } from '../../client/vueIntegration';
45
import { reportNuxtError } from '../utils';
56

67
// --- Types are copied from @sentry/vue (so it does not need to be exported) ---
@@ -53,7 +54,13 @@ export default defineNuxtPlugin({
5354
// Adding the Vue integration without the Vue error handler
5455
// Nuxt is registering their own error handler, which is unset after hydration: https://github.com/nuxt/nuxt/blob/d3fdbcaac6cf66d21e25d259390d7824696f1a87/packages/nuxt/src/app/entry.ts#L64-L73
5556
// 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
56-
sentryClient.addIntegration(vueIntegration({ app: vueApp, attachErrorHandler: false }));
57+
sentryClient.addIntegration(
58+
vueIntegration({
59+
...retrieveNuxtVueIntegrationOptions(),
60+
app: vueApp,
61+
attachErrorHandler: false,
62+
}),
63+
);
5764
}
5865
});
5966

packages/vue/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export { browserTracingIntegration } from './browserTracingIntegration';
55
export { attachErrorHandler } from './errorhandler';
66
export { createTracingMixins } from './tracing';
77
export { vueIntegration } from './integration';
8+
export type { VueIntegrationOptions } from './integration';
89
export { createSentryPiniaPlugin } from './pinia';

packages/vue/src/integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const DEFAULT_CONFIG: VueOptions = {
1919

2020
const INTEGRATION_NAME = 'Vue';
2121

22+
export type VueIntegrationOptions = Partial<VueOptions>;
23+
2224
export const vueIntegration = defineIntegration((integrationOptions: Partial<VueOptions> = {}) => {
2325
return {
2426
name: INTEGRATION_NAME,

0 commit comments

Comments
 (0)