Skip to content

Commit

Permalink
feat(tracing): enable Vue Router instrumentation by default (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Dec 19, 2022
1 parent 8b8fc3a commit acb2aaf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/content/en/sentry/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export default function () {
},
}
```
- 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/).
- 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 Integration](https://docs.sentry.io/platforms/javascript/guides/vue/configuration/integrations/vue-router/) is also automatically enabled. See all available [`BrowserTracing` options](https://docs.sentry.io/platforms/javascript/guides/vue/performance/instrumentation/automatic-instrumentation/).
- 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.
<alert type="info">
Expand Down
5 changes: 4 additions & 1 deletion lib/plugin.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export default async function (ctx, inject) {
<% if (options.tracing) { %>
// eslint-disable-next-line prefer-regex-literals
const { browserTracing, vueOptions, ...tracingOptions } = <%= serialize(options.tracing) %>
config.integrations.push(new BrowserTracing(browserTracing))
config.integrations.push(new BrowserTracing({
...(ctx.app.router ? { routingInstrumentation: Sentry.vueRouterInstrumentation(ctx.app.router) } : {}),
...browserTracing,
}))
merge(config, vueOptions, tracingOptions)
<% } %>
<% if (options.customClientIntegrations) { %>
Expand Down
19 changes: 16 additions & 3 deletions lib/plugin.lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async function loadSentry (ctx, inject) {
}
%>
const Sentry = await import(/* <%= magicComments.join(', ') %> */ '@sentry/vue')
<% if (options.tracing) { %>const { BrowserTracing } = await import(/* <%= magicComments.join(', ') %> */ '@sentry/tracing')<% } %>
<%
if (options.initialize) {
let integrations = options.PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations)
Expand All @@ -122,8 +123,7 @@ async function loadSentry (ctx, inject) {
const serializedConfig = Object
.entries({
...options.config,
...options.integrations.Vue,
...(options.tracing ? options.tracing.vueOptions.tracingOptions : {}),
...(options.tracing ? options.tracing.vueOptions : {}),
})
.map(([key, option]) => {
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
Expand Down Expand Up @@ -159,7 +159,20 @@ async function loadSentry (ctx, inject) {
}).join(',\n ')
%>,
]
/* eslint-enable quotes, key-spacing */
<% if (options.tracing) {
const serializedTracingConfig = Object
.entries(options.tracing.browserTracing)
.map(([key, option]) => {
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option)
return`${key}: ${value}`
})
.join(',\n ')
%>
config.integrations.push(new BrowserTracing({
...(ctx.app.router ? { routingInstrumentation: Sentry.vueRouterInstrumentation(ctx.app.router) } : {}),
<%= serializedTracingConfig %>
}))
<% } %>

<%if (options.customClientIntegrations) {%>
const customIntegrations = (await import(/* <%= magicComments.join(', ') %> */ '<%= options.customClientIntegrations %>').then(m => m.default || m))(ctx)
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/default/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<span id="server-side">{{ serverSentry ? 'Works!' : '$sentry object is missing!' }}</span>
<h3>Client-side</h3>
<span id="client-side">{{ clientSentry ? 'Works!' : '$sentry object is missing!' }}</span>
<p>
<button id="crash-button" @click="crash_me()">
crash me
</button>
</p>
</div>
</template>

Expand Down
1 change: 1 addition & 0 deletions test/fixture/lazy/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config = {
TryCatch: { eventTarget: false },
},
customClientIntegrations: '~/config/custom-client-integrations.js',
tracing: true,
},
publicRuntimeConfig: {
sentry: {
Expand Down

0 comments on commit acb2aaf

Please sign in to comment.