Skip to content

Commit 0d6b0a5

Browse files
committed
feat: migrate to sentry v7
1 parent 07fb5ce commit 0d6b0a5

File tree

14 files changed

+1406
-2448
lines changed

14 files changed

+1406
-2448
lines changed

docs/content/en/sentry/lazy-loading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can also pass a lazy config object in your module options (see [options](/se
2020
#### `$sentry` (mocked)
2121
- Type: `Object`
2222

23-
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
23+
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
2424

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

docs/content/en/sentry/options.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Normally, just setting DSN would be enough.
6868
- **mockApiMethods**
6969
- Type: `Boolean` or `Array`
7070
- Default `true`
71-
- Which API methods from `@sentry/browser` should be mocked. You can use this to only mock methods you really use.
71+
- Which API methods from `@sentry/vue` should be mocked. You can use this to only mock methods you really use.
7272
- This option is ignored when `injectMock: false`
7373
- If `mockApiMethods: true` then all available API methods will be mocked
7474
> If `injectMock: true` then _captureException_ will always be mocked for use with the window.onerror listener
@@ -233,8 +233,7 @@ Note that the module sets the following defaults when publishing is enabled:
233233
Dedupe: {},
234234
ExtraErrorData: {},
235235
ReportingObserver: {},
236-
RewriteFrames: {},
237-
Vue: {attachProps: true, logErrors: this.options.dev}
236+
RewriteFrames: {}
238237
}
239238
```
240239
- 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.
@@ -307,7 +306,7 @@ export default function () {
307306
308307
<alert type="info">
309308
310-
`@sentry/tracing@6` (version 6 and not newer) should be installed manually when using this option.
309+
`@sentry/tracing@7` (version 7 and not newer) should be installed manually when using this option.
311310
312311
</alert>
313312
@@ -316,20 +315,13 @@ export default function () {
316315
```js
317316
{
318317
tracesSampleRate: 1.0,
319-
vueOptions: {
320-
tracing: true,
321-
tracingOptions: {
322-
hooks: [ 'mount', 'update' ],
323-
timeout: 2000,
324-
trackComponents: true
325-
}
326-
},
327-
browserOptions: {}
318+
trackComponents: true
319+
hooks: [ 'mount', 'update' ],
320+
timeout: 2000,
321+
tracePropagationTargets: ['localhost', /^\//]
328322
}
329323
```
330324
- Sentry documentation strongly recommends reducing the `tracesSampleRate` value; it should be between 0.0 and 1.0 (percentage of requests to capture)
331-
- The `vueOptions` are passed to the `Vue` integration, see https://docs.sentry.io/platforms/javascript/guides/vue/#monitor-performance for more information
332-
- `browserOptions` are passed to the `BrowserTracing` integration, see https://github.com/getsentry/sentry-javascript/tree/master/packages/tracing for more information
333325
334326
### config
335327

lib/core/options.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import merge from 'lodash.mergewith'
22
import * as Integrations from '@sentry/integrations'
33
import { canInitialize } from './utils'
44

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

@@ -74,7 +74,7 @@ function resolveLazyOptions (options, apiMethods, logger) {
7474

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

8080
if (!options.lazy.mockApiMethods.includes('captureException')) {
@@ -96,16 +96,10 @@ function resolveTracingOptions (tracing, config) {
9696
/** @type {NonNullable<import('../../types/sentry').TracingConfiguration>} */
9797
const tracingOptions = merge(
9898
{
99-
tracesSampleRate: 1.0,
100-
vueOptions: {
101-
tracing: true,
102-
tracingOptions: {
103-
hooks: ['mount', 'update'],
104-
timeout: 2000,
105-
trackComponents: true,
106-
},
107-
},
108-
browserOptions: {},
99+
hooks: ['mount', 'update'],
100+
timeout: 2000,
101+
trackComponents: true,
102+
tracePropagationTargets: ['localhost', /^\//],
109103
},
110104
typeof tracing === 'boolean' ? {} : tracing,
111105
)
@@ -126,7 +120,7 @@ export async function resolveClientOptions (moduleContainer, moduleOptions, logg
126120

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

129-
const apiMethods = await getApiMethods('@sentry/browser')
123+
const apiMethods = await getApiMethods('@sentry/vue')
130124
resolveLazyOptions(options, apiMethods, logger)
131125
resolveTracingOptions(options.tracing, options.config)
132126

lib/module.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default function SentryModule (moduleOptions) {
3535
ExtraErrorData: {},
3636
ReportingObserver: {},
3737
RewriteFrames: {},
38-
Vue: { attachProps: true, logErrors: this.options.dev },
3938
},
4039
serverIntegrations: {
4140
Dedupe: {},

lib/plugin.client.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import VueLib from 'vue'
1+
import Vue from 'vue'
22
import merge from 'lodash.mergewith'
3-
import * as Sentry from '@sentry/browser'
3+
import * as Sentry from '@sentry/vue'
44
<%
55
if (options.initialize) {
66
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
@@ -15,14 +15,15 @@ const { <%= integrations.join(', ') %> } = Sentry.Integrations
1515
}
1616
%>
1717
<% if (options.tracing) { %>
18-
import { Integrations as TracingIntegrations } from '@sentry/tracing'
18+
import { BrowserTracing } from "@sentry/tracing";
1919
<% } %>
2020

2121
// eslint-disable-next-line require-await
2222
export default async function (ctx, inject) {
2323
<% if (options.initialize) { %>
2424
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
2525
const config = {
26+
Vue,
2627
<%= Object.entries(options.config).map(([key, option]) =>
2728
typeof option === 'function'
2829
? `${key}:${serializeFunction(option)}`
@@ -37,13 +38,6 @@ export default async function (ctx, inject) {
3738

3839
config.integrations = [
3940
<%= Object.entries(options.integrations).map(([name, integration]) => {
40-
if (name === 'Vue') {
41-
if (options.tracing) {
42-
integration = { ...integration, ...options.tracing.vueOptions }
43-
}
44-
return `new ${name}({ Vue: VueLib, ...${serialize(integration)}})`
45-
}
46-
4741
const integrationOptions = Object.entries(integration).map(([key, option]) =>
4842
typeof option === 'function'
4943
? `${key}:${serializeFunction(option)}`
@@ -54,7 +48,10 @@ export default async function (ctx, inject) {
5448
}).join(',\n ')%>,
5549
]
5650
<% if (options.tracing) { %>
57-
config.integrations.push(<%= `new TracingIntegrations.BrowserTracing(${serialize(options.tracing.browserOptions)})` %>)
51+
const { tracePropagationTargets, ...tracingOptions } = options.tracing
52+
53+
config.integrations.push(new BrowserTracing({ tracePropagationTargets }))
54+
merge(config, tracingOptions)
5855
<% } %>
5956
<% if (options.customClientIntegrations) { %>
6057
const customIntegrations = await getCustomIntegrations(ctx)

lib/plugin.lazy.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async function loadSentry (ctx, inject) {
110110
magicComments.push('webpackPreload: true')
111111
}
112112
%>
113-
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/browser')
113+
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/vue')
114114
<%
115115
if (options.initialize) {
116116
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
@@ -122,6 +122,7 @@ async function loadSentry (ctx, inject) {
122122
%>
123123
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
124124
const config = <%= serialize(options.config) %>
125+
config.Vue = VueLib
125126

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

132133
config.integrations = [
133134
<%= Object.entries(options.integrations).map(([name, integration]) => {
134-
if (name === 'Vue') {
135-
return `new ${name}({ Vue: VueLib, ...${serialize(integration)}})`
136-
}
137-
138135
const integrationOptions = Object.entries(integration).map(([key, option]) =>
139136
typeof option === 'function'
140137
? `${key}:${serializeFunction(option)}`

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
}
5151
},
5252
"dependencies": {
53-
"@sentry/browser": "^6.19.7",
54-
"@sentry/integrations": "^6.19.7",
55-
"@sentry/node": "^6.19.7",
53+
"@sentry/integrations": "^7.23.0",
54+
"@sentry/node": "^7.23.0",
55+
"@sentry/vue": "^7.23.0",
5656
"consola": "^2.15.3",
5757
"lodash.mergewith": "^4.6.2"
5858
},
@@ -63,7 +63,7 @@
6363
"@nuxtjs/eslint-config-typescript": "^11.0.0",
6464
"@nuxtjs/module-test-utils": "^1.6.3",
6565
"@release-it/conventional-changelog": "^5.1.0",
66-
"@sentry/tracing": "^6.19.7",
66+
"@sentry/tracing": "^7.23.0",
6767
"@sentry/webpack-plugin": "^1.19.0",
6868
"@types/jest": "^29.0.3",
6969
"@types/lodash.mergewith": "^4.6.7",
@@ -80,6 +80,7 @@
8080
"playwright-chromium": "^1.26.1",
8181
"release-it": "^15.4.2",
8282
"sentry-testkit": "^4.0.3",
83-
"typescript": "^4.8.4"
83+
"typescript": "^4.8.4",
84+
"vue": "2.7.14"
8485
}
8586
}

test/fixture/default/pages/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
export default {
1212
data () {
1313
return {
14-
/** @type {import('@sentry/minimal') | null} */
14+
/** @type {import('@sentry/core') | null} */
1515
clientSentry: null,
16-
/** @type {import('@sentry/minimal') | null} */
16+
/** @type {import('@sentry/core') | null} */
1717
serverSentry: this.$sentry,
1818
}
1919
},

test/fixture/lazy/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
data () {
1313
return {
1414
isSentryReady: false,
15-
/** @type {import('@sentry/minimal') | null} */
15+
/** @type {import('@sentry/core') | null} */
1616
serverSentry: this.$sentry,
1717
}
1818
},

test/fixture/with-lazy-config/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
data () {
1313
return {
1414
isSentryReady: false,
15-
/** @type {import('@sentry/minimal') | null} */
15+
/** @type {import('@sentry/core') | null} */
1616
serverSentry: this.$sentry,
1717
}
1818
},

0 commit comments

Comments
 (0)