Skip to content

Commit 7200c3c

Browse files
committed
feat(tracing): enable Vue Router instrumentation by default
1 parent 068a879 commit 7200c3c

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

docs/content/en/sentry/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export default function () {
327327
},
328328
}
329329
```
330-
- On the browser side the `BrowserTracing` integration is enabled by default and adds automatic instrumentation for monitoring the performance of the application. See available [`BrowserTracing` options](https://docs.sentry.io/platforms/javascript/guides/vue/performance/instrumentation/automatic-instrumentation/).
330+
- On the browser side the `BrowserTracing` integration is enabled by default and adds automatic instrumentation for monitoring the performance of the application. The Vue Router instrumentation (`Sentry.vueRouterInstrumentation`) is also automatically enabled. See all available [`BrowserTracing` options](https://docs.sentry.io/platforms/javascript/guides/vue/performance/instrumentation/automatic-instrumentation/).
331331
- On the browser side extra options for [Tracking Vue components](https://docs.sentry.io/platforms/javascript/guides/vue/features/component-tracking/) can be passed through the `vueOptions` object.
332332
333333
<alert type="info">

lib/plugin.client.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export default async function (ctx, inject) {
5454
<% if (options.tracing) { %>
5555
// eslint-disable-next-line prefer-regex-literals
5656
const { browserTracing, vueOptions, ...tracingOptions } = <%= serialize(options.tracing) %>
57-
config.integrations.push(new BrowserTracing(browserTracing))
57+
config.integrations.push(new BrowserTracing({
58+
...(ctx.app.router ? { routingInstrumentation: Sentry.vueRouterInstrumentation(ctx.app.router) } : {}),
59+
...browserTracing,
60+
}))
5861
merge(config, vueOptions, tracingOptions)
5962
<% } %>
6063
<% if (options.customClientIntegrations) { %>

lib/plugin.lazy.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ async function loadSentry (ctx, inject) {
110110
}
111111
%>
112112
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/vue')
113+
<% if (options.tracing) { %>const { BrowserTracing } = await import(/* <%= magicComments.join(', ') %> */ '@sentry/tracing')<% } %>
113114
<%
114115
if (options.initialize) {
115116
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
@@ -122,8 +123,7 @@ async function loadSentry (ctx, inject) {
122123
const serializedConfig = Object
123124
.entries({
124125
...options.config,
125-
...options.integrations.Vue,
126-
...(options.tracing ? options.tracing.vueOptions.tracingOptions : {}),
126+
...(options.tracing ? options.tracing.vueOptions : {}),
127127
})
128128
.map(([key, option]) => {
129129
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
@@ -159,7 +159,20 @@ async function loadSentry (ctx, inject) {
159159
}).join(',\n ')
160160
%>,
161161
]
162-
/* eslint-enable quotes, key-spacing */
162+
<% if (options.tracing) {
163+
const serializedTracingConfig = Object
164+
.entries(options.tracing.browserTracing)
165+
.map(([key, option]) => {
166+
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
167+
return`${key}: ${value}`
168+
})
169+
.join(',\n ')
170+
%>
171+
config.integrations.push(new BrowserTracing({
172+
...(ctx.app.router ? { routingInstrumentation: Sentry.vueRouterInstrumentation(ctx.app.router) } : {}),
173+
<%= serializedTracingConfig %>
174+
}))
175+
<% } %>
163176

164177
<%if (options.customClientIntegrations) {%>
165178
const customIntegrations = (await import(/* <%= magicComments.join(', ') %> */ '<%= options.customClientIntegrations %>').then(m => m.default || m))(ctx)

test/default.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,17 @@ describe('Smoke test (default)', () => {
4444
expect(errors).toEqual([])
4545
})
4646

47+
test('reports error on crash', async () => {
48+
const page = await browser.newPage()
49+
await page.goto(url('/'))
50+
expect(await $$('#server-side', page)).toBe('Works!')
51+
expect(await $$('#client-side', page)).toBe('Works!')
52+
const crashButton = await page.$('#crash-button')
53+
expect(crashButton).not.toBeNull()
54+
await crashButton?.click()
55+
const reports = testkit.reports()
56+
expect(reports).toHaveLength(1)
57+
})
58+
4759
// TODO: Add tests for custom integration. Blocked by various sentry-kit bugs reported in its repo.
4860
})

test/fixture/default/pages/index.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<span id="server-side">{{ serverSentry ? 'Works!' : '$sentry object is missing!' }}</span>
55
<h3>Client-side</h3>
66
<span id="client-side">{{ clientSentry ? 'Works!' : '$sentry object is missing!' }}</span>
7+
<p>
8+
<button id="crash-button" @click="crash_me()">
9+
crash me
10+
</button>
11+
</p>
712
</div>
813
</template>
914

test/fixture/lazy/nuxt.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const config = {
2121
TryCatch: { eventTarget: false },
2222
},
2323
customClientIntegrations: '~/config/custom-client-integrations.js',
24+
tracing: true,
2425
},
2526
publicRuntimeConfig: {
2627
sentry: {

0 commit comments

Comments
 (0)