Skip to content

Commit 12e4ac5

Browse files
committed
Merge branch 'LukasHirt-feat/migrate-to-sentry-7' into beta
* LukasHirt-feat/migrate-to-sentry-7: lint consistent options serialization & filter out Vue integration options adjust types and tracing configuration feat: allow passing all browserTracing options chore: release 6.0.3
2 parents d3f1f3a + e366074 commit 12e4ac5

File tree

8 files changed

+78
-59
lines changed

8 files changed

+78
-59
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
'@nuxtjs/eslint-config-typescript',
2828
],
2929
rules: {
30+
'comma-dangle': 'off',
3031
'constructor-super': 'off', // ts(2335) & ts(2377)
3132
'getter-return': 'off', // ts(2378)
3233
'import/named': 'off',
@@ -54,6 +55,7 @@ module.exports = {
5455
'@typescript-eslint/adjacent-overload-signatures': 'error',
5556
'@typescript-eslint/ban-ts-comment': 'error',
5657
'@typescript-eslint/ban-types': 'error',
58+
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
5759
'@typescript-eslint/explicit-module-boundary-types': 'warn',
5860
'no-array-constructor': 'off',
5961
'@typescript-eslint/member-delimiter-style': ['error', { multiline: { delimiter: 'none', requireLast: false } }],

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
* migrate to sentry v7 ([0d6b0a5](https://github.com/nuxt-community/sentry-module/commit/0d6b0a55f512b50b37b0ac28ed140c6a835cd234))
99

10+
### [6.0.3](https://github.com/nuxt-community/sentry-module/compare/v6.0.2...v6.0.3) (2022-12-13)
11+
1012

1113
### Bug Fixes
1214

@@ -527,4 +529,4 @@ All notable changes to this project will be documented in this file. See [standa
527529

528530

529531
<a name="0.0.2"></a>
530-
## [0.0.2](https://github.com/nuxt-community/sentry-module/compare/v0.0.1...v0.0.2) (2017-10-17)
532+
## [0.0.2](https://github.com/nuxt-community/sentry-module/compare/v0.0.1...v0.0.2) (2017-10-17)

docs/content/en/guide/setup.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ Then, add `@nuxtjs/sentry` to the `modules` section of `nuxt.config.js`:
4949
}
5050
```
5151

52+
<alert type="info">
53+
54+
For Typescript or type-checked JavaScript projects, you might have to install the `@sentry/tracing` package even when not using the tracing functionality. In that case, the package can be installed as a dev-only dependency.
55+
56+
</alert>
57+
5258
## Types
5359

54-
For typescript projects, add `@nuxtjs/sentry` to tsconfig types array
60+
In Typescript or type-checked JavaScript projects, add `@nuxtjs/sentry` to the `types` array in `tsconfig.json` to enable module types.
5561

5662
```json [tsconfig.json]
5763
{
@@ -65,4 +71,4 @@ For typescript projects, add `@nuxtjs/sentry` to tsconfig types array
6571

6672
## Configuration
6773

68-
See [Options](/sentry/options) for a list of available options
74+
See [Options](/sentry/options) for a list of available options.

docs/content/en/sentry/options.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,11 @@ export default function () {
316316
{
317317
tracesSampleRate: 1.0,
318318
trackComponents: true
319-
hooks: [ 'mount', 'update' ],
320-
timeout: 2000,
321-
tracePropagationTargets: ['localhost', /^\//]
319+
browserTracing: {}
322320
}
323321
```
324322
- Sentry documentation strongly recommends reducing the `tracesSampleRate` value; it should be between 0.0 and 1.0 (percentage of requests to capture)
323+
- See available [browserTracing options](https://docs.sentry.io/platforms/javascript/guides/vue/performance/instrumentation/automatic-instrumentation/#configuration-options)
325324
326325
### config
327326

lib/core/options.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ function resolveTracingOptions (options, config) {
9898
const tracingOptions = merge(
9999
{
100100
tracesSampleRate: 1,
101-
hooks: ['mount', 'update'],
102-
timeout: 2000,
103101
trackComponents: true,
104-
tracePropagationTargets: ['localhost', /^\//],
102+
browserTracing: {},
105103
},
106104
userOptions,
107105
)

lib/plugin.client.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export default async function (ctx, inject) {
2222
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
2323
const config = {
2424
Vue,
25-
<%= Object.entries(options.config).map(([key, option]) =>
26-
typeof option === 'function'
27-
? `${key}:${serializeFunction(option)}`
28-
: `${key}:${serialize(option)}`
29-
).join(',\n ') %>,
25+
<%= Object
26+
.entries(options.config)
27+
.map(([key, option]) => {
28+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
29+
return `${key}:${value}`
30+
})
31+
.join(',\n ') %>,
3032
}
3133

3234
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
@@ -35,20 +37,25 @@ export default async function (ctx, inject) {
3537
}
3638

3739
config.integrations = [
38-
<%= Object.entries(options.integrations).map(([name, integration]) => {
39-
const integrationOptions = Object.entries(integration).map(([key, option]) =>
40-
typeof option === 'function'
41-
? `${key}:${serializeFunction(option)}`
42-
: `${key}:${serialize(option)}`
43-
)
40+
<%= Object
41+
.entries(options.integrations)
42+
.filter(([name]) => name !== 'Vue')
43+
.map(([name, integration]) => {
44+
const integrationOptions = Object
45+
.entries(integration)
46+
.map(([key, option]) => {
47+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
48+
return `${key}:${value}`
49+
})
4450

45-
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
46-
}).join(',\n ')%>,
51+
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
52+
})
53+
.join(',\n ') %>,
4754
]
4855
<% if (options.tracing) { %>
4956
// eslint-disable-next-line prefer-regex-literals
50-
const { tracePropagationTargets, ...tracingOptions } = <%= serialize(options.tracing) %>
51-
config.integrations.push(new BrowserTracing({ tracePropagationTargets }))
57+
const { browserTracing, ...tracingOptions } = <%= serialize(options.tracing) %>
58+
config.integrations.push(new BrowserTracing(browserTracing))
5259
merge(config, tracingOptions)
5360
<% } %>
5461
<% if (options.customClientIntegrations) { %>

lib/plugin.lazy.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import VueLib from 'vue'
1+
import Vue from 'vue'
22

33
<% if (options.lazy.injectMock) { %>
44
/* eslint-enable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
@@ -20,16 +20,16 @@ const delayUnhandledRejection = function (event) {
2020
delayedUnhandledRejections.push('reason' in event ? event.reason : 'detail' in event && 'reason' in event.detail ? event.detail.reason : event)
2121
}
2222

23-
const vueErrorHandler = VueLib.config.errorHandler
23+
const vueErrorHandler = Vue.config.errorHandler
2424

25-
VueLib.config.errorHandler = (error, vm, info) => {
25+
Vue.config.errorHandler = (error, vm, info) => {
2626
if (!loadCompleted) {
2727
if (vm) {
2828
vm.$sentry.captureException(error)
2929
}
3030

31-
if (VueLib.util) {
32-
VueLib.util.warn(`Error in ${info}: "${error.toString()}"`, vm)
31+
if (Vue.util) {
32+
Vue.util.warn(`Error in ${info}: "${error.toString()}"`, vm)
3333
}
3434
console.error(error)
3535
}
@@ -119,10 +119,24 @@ async function loadSentry (ctx, inject) {
119119
integrations = options.BROWSER_INTEGRATIONS.filter(key => key in options.integrations)
120120
if (integrations.length) {%> const { <%= integrations.join(', ') %> } = Sentry.Integrations
121121
<%}
122+
123+
const serializedConfig = Object
124+
.entries({
125+
...options.config,
126+
...options.integrations.Vue,
127+
...(options.tracing ? options.tracing.vueOptions.tracingOptions : {}),
128+
})
129+
.map(([key, option]) => {
130+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
131+
return`${key}: ${value}`
132+
})
133+
.join(',\n ')
122134
%>
123135
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
124-
const config = <%= serialize(options.config) %>
125-
config.Vue = VueLib
136+
const config = {
137+
Vue,
138+
<%= serializedConfig %>,
139+
}
126140

127141
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
128142
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) {
@@ -131,16 +145,22 @@ async function loadSentry (ctx, inject) {
131145
}
132146

133147
config.integrations = [
134-
<%= Object.entries(options.integrations).map(([name, integration]) => {
135-
const integrationOptions = Object.entries(integration).map(([key, option]) =>
136-
typeof option === 'function'
137-
? `${key}:${serializeFunction(option)}`
138-
: `${key}:${serialize(option)}`
139-
)
140-
141-
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
142-
}).join(',\n ')%>,
148+
<%= Object
149+
.entries(options.integrations)
150+
.filter(([name]) => name !== 'Vue')
151+
.map(([name, integration]) => {
152+
const integrationOptions = Object
153+
.entries(integration)
154+
.map(([key, option]) => {
155+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
156+
return `${key}:${value}`
157+
})
158+
159+
return `new ${name}(${integrationOptions.length ? '{' + integrationOptions.join(',') + '}' : ''})`
160+
}).join(',\n ')
161+
%>,
143162
]
163+
144164
<%if (options.customClientIntegrations) {%>
145165
const customIntegrations = (await import(/* <%= magicComments.join(', ') %> */ '<%= options.customClientIntegrations %>').then(m => m.default || m))(ctx)
146166
if (Array.isArray(customIntegrations)) {

types/sentry.d.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { IncomingMessage, ServerResponse } from 'http'
33
import { Options as WebpackOptions } from 'webpack'
4+
import { BrowserTracing } from '@sentry/tracing'
45
import { Options as SentryOptions } from '@sentry/types'
5-
import type { Options as SentryVueOptions } from '@sentry/vue/types/types'
6+
import { Options as SentryVueOptions, TracingOptions as SentryVueTracingOptions } from '@sentry/vue/types/types'
67
import { SentryCliPluginOptions } from '@sentry/webpack-plugin'
78
import { Handlers } from '@sentry/node'
89

@@ -22,24 +23,8 @@ export interface LazyConfiguration {
2223
webpackPreload?: boolean
2324
}
2425

25-
declare type Operation = 'activate' | 'create' | 'destroy' | 'mount' | 'update'
26-
export interface TracingConfiguration {
27-
tracesSampleRate?: number
28-
/**
29-
* Decides whether to track components by hooking into its lifecycle methods.
30-
* Can be either set to `boolean` to enable/disable tracking for all of them.
31-
* Or to an array of specific component names (case-sensitive).
32-
*/
33-
trackComponents: boolean | string[]
34-
/** How long to wait until the tracked root activity is marked as finished and sent of to Sentry */
35-
timeout: number
36-
/**
37-
* List of hooks to keep track of during component lifecycle.
38-
* Available hooks: 'activate' | 'create' | 'destroy' | 'mount' | 'update'
39-
* Based on https://vuejs.org/v2/api/#Options-Lifecycle-Hooks
40-
*/
41-
hooks: Operation[]
42-
tracePropagationTargets: (string|RegExp)[]
26+
export interface TracingConfiguration extends Partial<SentryVueTracingOptions>, Pick<SentryOptions, 'tracesSampleRate'> {
27+
browserTracing?: Partial<BrowserTracing['options']>
4328
}
4429

4530
export interface ModuleConfiguration {

0 commit comments

Comments
 (0)