-
-
Notifications
You must be signed in to change notification settings - Fork 38
Ref(V3): Refactor init & drop deprecated omit. #1046
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,6 @@ const app = createApp(App) | |
|
|
||
|
|
||
| Sentry.init({ | ||
| app, | ||
| dsn: 'https://[email protected]/4505912397660160', | ||
| integrations: [ | ||
| SentryVue.vueIntegration({ | ||
|
|
@@ -59,11 +58,18 @@ Sentry.init({ | |
| enableLogs: true, | ||
| beforeSendLog: (log) => { | ||
| return log; | ||
| } | ||
| }, | ||
|
|
||
| siblingOptions: { | ||
| vueOptions: { | ||
| app: app, | ||
| attachErrorHandler: false, | ||
| attachProps: false, | ||
| }, | ||
| }, | ||
| }, | ||
| // Forward the init method from @sentry/vue | ||
| SentryVue.init | ||
| SentryVue.init, | ||
| ); | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,16 +17,19 @@ import { NATIVE } from './wrapper'; | |
| * @param options Options for the SDK | ||
| * @param originalInit The init function of the sibling SDK, leave blank to initialize with `@sentry/browser` | ||
| */ | ||
| export function init<T>( | ||
| passedOptions: CapacitorOptions & T, | ||
| originalInit: (passedOptions: T & BrowserOptions) => void = browserInit, | ||
| export function init( | ||
| passedOptions: CapacitorOptions, | ||
| originalInit: (passedOptions:BrowserOptions) => void = browserInit, | ||
| ): void { | ||
|
|
||
| const finalOptions = { | ||
| enableAutoSessionTracking: true, | ||
| enableWatchdogTerminationTracking: true, | ||
| enableCaptureFailedRequests: false, | ||
| ...passedOptions, | ||
| }; | ||
| finalOptions.siblingOptions && delete finalOptions.siblingOptions; | ||
|
|
||
| if (finalOptions.enabled === false || NATIVE.platform === 'web') { | ||
|
Comment on lines
30
to
33
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want to be present, we actually want it to be together with the other options when setting the browser options, like |
||
| finalOptions.enableNative = false; | ||
| finalOptions.enableNativeNagger = false; | ||
|
|
@@ -38,26 +41,26 @@ export function init<T>( | |
| // const capacitorHub = new Hub(undefined, new CapacitorScope()); | ||
| // makeMain(capacitorHub); | ||
| const defaultIntegrations: false | Integration[] = | ||
| passedOptions.defaultIntegrations === undefined | ||
| passedOptions.defaultIntegrations === undefined | ||
| ? getDefaultIntegrations(passedOptions) | ||
| : passedOptions.defaultIntegrations; | ||
| : passedOptions.defaultIntegrations; | ||
|
|
||
| finalOptions.integrations = getIntegrationsToSetup({ | ||
| integrations: safeFactory(passedOptions.integrations, { | ||
| integrations: safeFactory(passedOptions.integrations, { | ||
| loggerMessage: 'The integrations threw an error', | ||
| }), | ||
| defaultIntegrations, | ||
| }); | ||
|
|
||
| if ( | ||
| finalOptions.enableNative && | ||
| !passedOptions.transport && | ||
| !passedOptions.transport && | ||
| NATIVE.platform !== 'web' | ||
| ) { | ||
| finalOptions.transport = passedOptions.transport || makeNativeTransport; | ||
| finalOptions.transport = passedOptions.transport || makeNativeTransport; | ||
|
|
||
| finalOptions.transportOptions = { | ||
| ...(passedOptions.transportOptions ?? {}), | ||
| ...(passedOptions.transportOptions ?? {}), | ||
| bufferSize: DEFAULT_BUFFER_SIZE, | ||
| }; | ||
| } | ||
|
|
@@ -72,18 +75,19 @@ export function init<T>( | |
| } | ||
|
|
||
| const browserOptions = { | ||
| ...passedOptions.siblingOptions?.vueOptions, | ||
| ...passedOptions.siblingOptions?.nuxtClientOptions, | ||
| ...finalOptions, | ||
| autoSessionTracking: | ||
| NATIVE.platform === 'web' && finalOptions.enableAutoSessionTracking, | ||
| } as BrowserOptions & T; | ||
| } as BrowserOptions; | ||
|
Comment on lines
75
to
+83
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BrowserOptions is a common type, and it's used for Angular/React. It's also the same type for Vue/Nuxt with additional parameters. |
||
|
|
||
| const mobileOptions = { | ||
| ...finalOptions, | ||
| enableAutoSessionTracking: | ||
| NATIVE.platform !== 'web' && finalOptions.enableAutoSessionTracking, | ||
| } as CapacitorClientOptions; | ||
|
|
||
|
|
||
| sdkInit(browserOptions, mobileOptions, originalInit, passedOptions.transport); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
|
|
||
| export type { VueOptions } from './vueOptions'; | ||
| export type { NuxtOptions } from './nuxtOptions'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import type { VueOptions } from './vueOptions'; | ||
|
|
||
| export type NuxtOptions = Omit<VueOptions, 'app'>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import type { BrowserOptions } from '@sentry/browser'; | ||
| // FILE SYNCED WITH https://github.com/getsentry/sentry-javascript/blob/develop/packages/vue/src/types.ts | ||
|
|
||
| // This is not great, but kinda necessary to make it work with Vue@2 and Vue@3 at the same time. | ||
| export interface Vue { | ||
| config: { | ||
| errorHandler?: any; | ||
| warnHandler?: any; | ||
| silent?: boolean; | ||
| }; | ||
| mixin: (mixins: Partial<Record<Hook, any>>) => void; | ||
| } | ||
|
|
||
| export type ViewModel = { | ||
| _isVue?: boolean; | ||
| __isVue?: boolean; | ||
| $root: ViewModel; | ||
| $parent?: ViewModel; | ||
| $props: { [key: string]: any }; | ||
| $options?: { | ||
| name?: string; | ||
| propsData?: { [key: string]: any }; | ||
| _componentTag?: string; | ||
| __file?: string; | ||
| __name?: string; | ||
| }; | ||
| }; | ||
|
|
||
| export interface VueOptions { | ||
| /** Vue constructor to be used inside the integration (as imported by `import Vue from 'vue'` in Vue2) */ | ||
| Vue?: Vue; | ||
|
|
||
| /** | ||
| * Vue app instance(s) to be used inside the integration (as generated by `createApp` in Vue3). | ||
| */ | ||
| app?: Vue | Vue[]; | ||
|
|
||
| /** | ||
| * When set to `false`, Sentry will suppress reporting of all props data | ||
| * from your Vue components for privacy concerns. | ||
| */ | ||
| attachProps: boolean; | ||
|
|
||
| /** | ||
| * By default, Sentry attaches an error handler to capture exceptions and report them to Sentry. | ||
| * When `attachErrorHandler` is set to `false`, automatic error reporting is disabled. | ||
| * | ||
| * Usually, this option should stay enabled, unless you want to set up Sentry error reporting yourself. | ||
| * For example, the Sentry Nuxt SDK does not attach an error handler as it's using the error hooks provided by Nuxt. | ||
| * | ||
| * @default true | ||
|
Comment on lines
+40
to
+52
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep it as is since it's an exact copy of Vue options. |
||
| */ | ||
| attachErrorHandler: boolean; | ||
|
|
||
| /** {@link TracingOptions} */ | ||
| tracingOptions?: Partial<TracingOptions>; | ||
| } | ||
|
|
||
| export type Options = BrowserOptions & VueOptions; | ||
|
|
||
| /** Vue specific configuration for Tracing Integration */ | ||
| export interface TracingOptions { | ||
| /** | ||
| * Decides whether to track components by hooking into its lifecycle methods. | ||
| * Can be either set to `boolean` to enable/disable tracking for all of them. | ||
| * Or to an array of specific component names (case-sensitive). | ||
| */ | ||
| trackComponents: boolean | string[]; | ||
|
|
||
| /** How long to wait until the tracked root activity is marked as finished and sent of to Sentry */ | ||
| timeout: number; | ||
|
|
||
| /** | ||
| * List of hooks to keep track of during component lifecycle. | ||
| * Available hooks: 'activate' | 'create' | 'destroy' | 'mount' | 'unmount' | 'update' | ||
| * Based on https://vuejs.org/v2/api/#Options-Lifecycle-Hooks | ||
| */ | ||
| hooks: Operation[]; | ||
| } | ||
|
|
||
| export type Hook = | ||
| | 'activated' | ||
| | 'beforeCreate' | ||
| | 'beforeDestroy' | ||
| | 'beforeUnmount' | ||
| | 'beforeMount' | ||
| | 'beforeUpdate' | ||
| | 'created' | ||
| | 'deactivated' | ||
| | 'destroyed' | ||
| | 'unmounted' | ||
| | 'mounted' | ||
| | 'updated'; | ||
|
|
||
| export type Operation = 'activate' | 'create' | 'destroy' | 'mount' | 'update' | 'unmount'; | ||
Uh oh!
There was an error while loading. Please reload this page.