Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
2 changes: 1 addition & 1 deletion docs/content/en/sentry/lazy-loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You can also pass a lazy config object in your module options (see [options](/se
#### `$sentry` (mocked)
- Type: `Object`

Normally `$sentry` would always refer to the `@sentry/browser` API. But if we lazy load Sentry this API wont be available until Sentry has loaded. If you don't want to worry about whether Sentry is loaded or not, a mocked Sentry API is injected into the Nuxt.js context that will execute all Sentry API calls once Sentry is loaded
Normally `$sentry` would always refer to the `@sentry/vue` API. But if we lazy load Sentry this API wont be available until Sentry has loaded. If you don't want to worry about whether Sentry is loaded or not, a mocked Sentry API is injected into the Nuxt.js context that will execute all Sentry API calls once Sentry is loaded

See: [`injectMock`](/sentry/options#lazy) and [`mockApiMethods`](/sentry/options#lazy) options.

Expand Down
23 changes: 8 additions & 15 deletions docs/content/en/sentry/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Normally, just setting DSN would be enough.
- **mockApiMethods**
- Type: `Boolean` or `Array`
- Default `true`
- Which API methods from `@sentry/browser` should be mocked. You can use this to only mock methods you really use.
- Which API methods from `@sentry/vue` should be mocked. You can use this to only mock methods you really use.
- This option is ignored when `injectMock: false`
- If `mockApiMethods: true` then all available API methods will be mocked
> If `injectMock: true` then _captureException_ will always be mocked for use with the window.onerror listener
Expand Down Expand Up @@ -233,8 +233,7 @@ Note that the module sets the following defaults when publishing is enabled:
Dedupe: {},
ExtraErrorData: {},
ReportingObserver: {},
RewriteFrames: {},
Vue: {attachProps: true, logErrors: this.options.dev}
RewriteFrames: {}
}
```
- Sentry by default also enables these browser integrations: `InboundFilters`, `FunctionToString`, `TryCatch`, `Breadcrumbs`, `GlobalHandlers`, `LinkedErrors`, `UserAgent`. Their options can be overridden by specifying them manually in the object.
Expand Down Expand Up @@ -307,7 +306,7 @@ export default function () {

<alert type="info">

`@sentry/tracing@6` (version 6 and not newer) should be installed manually when using this option.
`@sentry/tracing@7` (version 7 and not newer) should be installed manually when using this option.

</alert>

Expand All @@ -316,20 +315,14 @@ export default function () {
```js
{
tracesSampleRate: 1.0,
vueOptions: {
tracing: true,
tracingOptions: {
hooks: [ 'mount', 'update' ],
timeout: 2000,
trackComponents: true
}
},
browserOptions: {}
trackComponents: true
hooks: [ 'mount', 'update' ],
timeout: 2000,
browserTracing: {}
}
```
- Sentry documentation strongly recommends reducing the `tracesSampleRate` value; it should be between 0.0 and 1.0 (percentage of requests to capture)
- The `vueOptions` are passed to the `Vue` integration, see https://docs.sentry.io/platforms/javascript/guides/vue/#monitor-performance for more information
- `browserOptions` are passed to the `BrowserTracing` integration, see https://github.com/getsentry/sentry-javascript/tree/master/packages/tracing for more information
- Available browserTracing options can be found [here](https://docs.sentry.io/platforms/javascript/guides/vue/performance/instrumentation/automatic-instrumentation/#configuration-options)

### config

Expand Down
21 changes: 8 additions & 13 deletions lib/core/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import merge from 'lodash.mergewith'
import * as Integrations from '@sentry/integrations'
import { canInitialize } from './utils'

export const PLUGGABLE_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'ReportingObserver', 'RewriteFrames', 'Vue']
export const PLUGGABLE_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'ReportingObserver', 'RewriteFrames']
export const BROWSER_INTEGRATIONS = ['InboundFilters', 'FunctionToString', 'TryCatch', 'Breadcrumbs', 'GlobalHandlers', 'LinkedErrors', 'UserAgent']
const SERVER_INTEGRATIONS = ['CaptureConsole', 'Debug', 'Dedupe', 'ExtraErrorData', 'RewriteFrames', 'Modules', 'Transaction']

Expand Down Expand Up @@ -74,7 +74,7 @@ function resolveLazyOptions (options, apiMethods, logger) {

const notfoundMethods = mockMethods.filter(method => !apiMethods.includes(method))
if (notfoundMethods.length) {
logger.warn('Some specified methods to mock weren\'t found in @sentry/browser:', notfoundMethods)
logger.warn('Some specified methods to mock weren\'t found in @sentry/vue:', notfoundMethods)
}

if (!options.lazy.mockApiMethods.includes('captureException')) {
Expand All @@ -97,16 +97,11 @@ function resolveTracingOptions (options, config) {
/** @type {NonNullable<import('../../types/sentry').TracingConfiguration>} */
const tracingOptions = merge(
{
tracesSampleRate: 1.0,
vueOptions: {
tracing: true,
tracingOptions: {
hooks: ['mount', 'update'],
timeout: 2000,
trackComponents: true,
},
},
browserOptions: {},
tracesSampleRate: 1,
hooks: ['mount', 'update'],
timeout: 2000,
trackComponents: true,
browserTracing: {},
},
userOptions,
)
Expand All @@ -128,7 +123,7 @@ export async function resolveClientOptions (moduleContainer, moduleOptions, logg

options.config = merge({}, options.config, options.clientConfig)

const apiMethods = await getApiMethods('@sentry/browser')
const apiMethods = await getApiMethods('@sentry/vue')
resolveLazyOptions(options, apiMethods, logger)
resolveTracingOptions(options, options.config)

Expand Down
1 change: 0 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function SentryModule (moduleOptions) {
ExtraErrorData: {},
ReportingObserver: {},
RewriteFrames: {},
Vue: { attachProps: true, logErrors: this.options.dev },
},
serverIntegrations: {
Dedupe: {},
Expand Down
19 changes: 8 additions & 11 deletions lib/plugin.client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import VueLib from 'vue'
import Vue from 'vue'
import merge from 'lodash.mergewith'
import * as Sentry from '@sentry/browser'
<% if (options.tracing) { %>import { Integrations as TracingIntegrations } from '@sentry/tracing'<% } %>
import * as Sentry from '@sentry/vue'
<% if (options.tracing) { %>import { BrowserTracing } from '@sentry/tracing'<% } %>
<%
if (options.initialize) {
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
Expand All @@ -21,6 +21,7 @@ export default async function (ctx, inject) {
<% if (options.initialize) { %>
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
const config = {
Vue,
<%= Object.entries(options.config).map(([key, option]) =>
typeof option === 'function'
? `${key}:${serializeFunction(option)}`
Expand All @@ -35,13 +36,6 @@ export default async function (ctx, inject) {

config.integrations = [
<%= Object.entries(options.integrations).map(([name, integration]) => {
if (name === 'Vue') {
if (options.tracing) {
integration = { ...integration, ...options.tracing.vueOptions }
}
return `new ${name}({ Vue: VueLib, ...${serialize(integration)}})`
}

const integrationOptions = Object.entries(integration).map(([key, option]) =>
typeof option === 'function'
? `${key}:${serializeFunction(option)}`
Expand All @@ -52,7 +46,10 @@ export default async function (ctx, inject) {
}).join(',\n ')%>,
]
<% if (options.tracing) { %>
config.integrations.push(<%= `new TracingIntegrations.BrowserTracing(${Object.keys(options.tracing.browserOptions).length ? serialize(options.tracing.browserOptions) : ''})` %>)
// eslint-disable-next-line prefer-regex-literals
const { browserTracing, ...tracingOptions } = <%= serialize(options.tracing) %>
config.integrations.push(new BrowserTracing(browserTracing))
merge(config, tracingOptions)
<% } %>
<% if (options.customClientIntegrations) { %>
const customIntegrations = await getCustomIntegrations(ctx)
Expand Down
7 changes: 2 additions & 5 deletions lib/plugin.lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function loadSentry (ctx, inject) {
magicComments.push('webpackPreload: true')
}
%>
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/browser')
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/vue')
<%
if (options.initialize) {
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
Expand All @@ -122,6 +122,7 @@ async function loadSentry (ctx, inject) {
%>
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
const config = <%= serialize(options.config) %>
config.Vue = VueLib

const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) {
Expand All @@ -131,10 +132,6 @@ async function loadSentry (ctx, inject) {

config.integrations = [
<%= Object.entries(options.integrations).map(([name, integration]) => {
if (name === 'Vue') {
return `new ${name}({ Vue: VueLib, ...${serialize(integration)}})`
}

const integrationOptions = Object.entries(integration).map(([key, option]) =>
typeof option === 'function'
? `${key}:${serializeFunction(option)}`
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
}
},
"dependencies": {
"@sentry/browser": "^6.19.7",
"@sentry/integrations": "^6.19.7",
"@sentry/node": "^6.19.7",
"@sentry/integrations": "^7.23.0",
"@sentry/node": "^7.23.0",
"@sentry/vue": "^7.23.0",
"consola": "^2.15.3",
"lodash.mergewith": "^4.6.2"
},
Expand All @@ -63,7 +63,7 @@
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"@nuxtjs/module-test-utils": "^1.6.3",
"@release-it/conventional-changelog": "^5.1.1",
"@sentry/tracing": "^6.19.7",
"@sentry/tracing": "^7.23.0",
"@sentry/webpack-plugin": "^1.20.0",
"@types/jest": "^29.2.4",
"@types/lodash.mergewith": "^4.6.7",
Expand All @@ -80,6 +80,7 @@
"playwright-chromium": "^1.28.1",
"release-it": "^15.5.1",
"sentry-testkit": "^4.1.0",
"typescript": "4.8.4"
"typescript": "4.8.4",
"vue": "2.7.14"
}
}
4 changes: 2 additions & 2 deletions test/fixture/default/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
export default {
data () {
return {
/** @type {import('@sentry/minimal') | null} */
/** @type {import('@sentry/core') | null} */
clientSentry: null,
/** @type {import('@sentry/minimal') | null} */
/** @type {import('@sentry/core') | null} */
serverSentry: this.$sentry,
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/lazy/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
data () {
return {
isSentryReady: false,
/** @type {import('@sentry/minimal') | null} */
/** @type {import('@sentry/core') | null} */
serverSentry: this.$sentry,
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/with-lazy-config/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
data () {
return {
isSentryReady: false,
/** @type {import('@sentry/minimal') | null} */
/** @type {import('@sentry/core') | null} */
serverSentry: this.$sentry,
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/with-lazy-config/pages/mounted.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
data () {
return {
isSentryReady: false,
/** @type {import('@sentry/minimal') | null} */
/** @type {import('@sentry/core') | null} */
serverSentry: this.$sentry,
}
},
Expand Down
2 changes: 1 addition & 1 deletion types/extend.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'vue'
import 'vuex'
import * as SentryTypes from '@sentry/minimal'
import * as SentryTypes from '@sentry/core'
import { ModuleConfiguration } from './sentry'

// add type to Vue context
Expand Down
23 changes: 5 additions & 18 deletions types/sentry.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { IncomingMessage, ServerResponse } from 'http'
import { Options as WebpackOptions } from 'webpack'
import { BrowserTracing } from '@sentry/tracing'
import { Options as SentryOptions } from '@sentry/types'
import { BrowserOptions } from '@sentry/browser'
import type { Options as SentryVueOptions } from '@sentry/vue/types/types'
import { SentryCliPluginOptions } from '@sentry/webpack-plugin'
import { Handlers } from '@sentry/node'

Expand All @@ -24,12 +23,8 @@ export interface LazyConfiguration {
}

declare type Operation = 'activate' | 'create' | 'destroy' | 'mount' | 'update'
/**
* Vue specific configuration for Tracing Integration
* Not exported, so have to reproduce here
* @see https://github.com/getsentry/sentry-javascript/blob/master/packages/integrations/src/vue.ts
**/
interface TracingOptions {
export interface TracingConfiguration {
tracesSampleRate?: number
/**
* 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.
Expand All @@ -44,19 +39,11 @@ interface TracingOptions {
* Based on https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
*/
hooks: Operation[]
}

export interface TracingConfiguration {
tracesSampleRate?: number
vueOptions?: {
tracing?: boolean
tracingOptions?: Partial<TracingOptions>
}
browserOptions?: Partial<BrowserTracing['options']>
tracePropagationTargets: (string|RegExp)[]
}

export interface ModuleConfiguration {
clientConfig?: BrowserOptions
clientConfig?: Partial<SentryVueOptions>
clientIntegrations?: IntegrationsConfiguration
config?: SentryOptions
customClientIntegrations?: string
Expand Down
Loading