Track Vue Components

Learn how Sentry's Vue SDK allows you to monitor the rendering performance of your application and its components.

Sentry's Vue SDK offers a feature to monitor the performance of your Vue components: component tracking. Enabling this feature provides you with spans in your transactions that represent the component lifecycle events and durations. This allows you to get a drilled-down view into how your components are behaving so you can do things like identify slow initializations or frequent updates, which might have an impact on your app's performance.

By default, the Vue SDK tracks the rendering performance of your app (that is, its root component) on the initial page load. This operation is represented in the page load transaction by the ui.vue.render span.

You can also track your app's child components to get more details about the rendering process. This feature will create spans for each tracked component instance. The spans are called ui.vue.[hook] where [hook] is replaced by each tracked lifecycle stage. For example, the span representing the mount stage (the time between beforeMount and mounted) is called ui.vue.mount.

To set it up, add the Vue Integration to your Sentry.init() call and, set the tracingOptions.trackComponents option. Pass true to track all of your child components, or specify a list of individual comopnents you want to track:

Copied
import * as Sentry from "@sentry/vue";

Sentry.init({
  integrations: [
    Sentry.vueIntegration({
      tracingOptions: {
        trackComponents: true,
        // OR
        trackComponents: [
          "App",
          "RwvHeader",
          "RwvFooter",
          "RwvArticleList",
          "Pagination",
        ],
      },
    }),
  ],
});

The default value for trackComponents is false.

You can control which lifecycle hooks should be tracked. This is helpful if, for example, you want to know if some components are removed during the initial page load, in which case you can configure the integration to also track unmount hooks:

Copied
import * as Sentry from "@sentry/vue";

Sentry.init({
  integrations: [
    Sentry.vueIntegration({
      tracingOptions: {
        trackComponents: true
        hooks: ["mount", "update", "unmount"],
      },
    }),
  ],
});

The default set of tracked hooks is ['activate', 'mount', 'update'].

The following hooks are available to track in Vue 3: ['activate', 'create', 'unmount', 'mount', 'update']

Note that when specifying hooks, we use the simple verb rather than before and -ed pairs. For example, unmount is correct, while beforeUnmount and unmounted are incorrect.

You can specify how long the root rendering span should wait for the last component to render by configuring the timeout option in milliseconds. Every new rendering cycle debounces the timeout, and it starts counting from the beginning. Once the timeout is reached, tracking is completed, and all the rendering information is sent to Sentry:

Copied
import * as Sentry from "@sentry/vue";

Sentry.init({
  integrations: [
    Sentry.vueIntegration({
      tracingOptions: {
        trackComponents: true,
        timeout: 500, // milliseconds
      },
    }),
  ],
});

The default timeout is 2000 milliseconds.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").