Skip to content

Instruct to use the recommended way of using Vue component tracking #11917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ Sentry.init({

Note, that when you use this property there is no change in behaviour, as opposed to when you use the three top-level properties described above.

The default value for `tracingOptions` is `undefined`.
The default value for `tracingOptions` is `undefined`.
105 changes: 52 additions & 53 deletions docs/platforms/javascript/guides/vue/features/component-tracking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: "Learn how Sentry's Vue SDK allows you to monitor the rendering per
sidebar_order: 10
---

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 life cycle 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.
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.

## Usage

Expand All @@ -18,87 +18,86 @@ To set up component tracking, you need to configure tracing. For details on how

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.

### Child Components
### Child Component Tracking

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, at minimum, [`trackComponents`](#trackcomponents) in your `Sentry.init` call. Optionally, you can also add [`hooks`](#hooks), and [`timeout`](#timeout).
To set it up, add the Vue Integration to your `Sentry.init()` call and, set the `tracingOptions.trackComponents` option.
Set the `trackComponent` option to `true` to track all of your child components, or specify a list of individual comopnents you want to track:

#### `trackComponents`
```javascript {5-17}
import * as Sentry from "@sentry/vue";

This is the main option that controls which child components should be tracked. Set it to `true` to track all of them or specify a list of individual components you want to track:

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

The default is `false`.
The default value for `trackComponents` is `false`.

#### Track Specific Component Lifecycle Hooks

#### `hooks`
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:

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 add a `unmount` hook to the default:
```javascript {8}
import * as Sentry from "@sentry/vue";

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

The following hooks are available to track in Vue 3: `['activate', 'create', 'unmount', 'mount', 'update']`
The default set of tracked hooks is `['activate', 'mount', 'update']`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another item in the v9 list to remove update as a hook to track by default, right? No action required, was just remembering that we discussed this


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.
The following hooks are available to track in Vue 3: `['activate', 'create', 'unmount', 'mount', 'update']`

<Alert>

In Vue 2, use `destroy` instead of `unmount`. `destroy` does not work in Vue 3, as the names of the lifecycle hooks themselves [changed](https://v3-migration.vuejs.org/breaking-changes/#other-minor-changes) in Vue 3.
In Vue 2, use `destroy` instead of `unmount`. `destroy` does not work in Vue 3, as the names of the lifecycle hooks [changed](https://v3-migration.vuejs.org/breaking-changes/#other-minor-changes) in Vue 3.

</Alert>

The default set of hooks is `['activate', '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.

#### `timeout`
#### Configure a Timeout for Component Tracking

You can specify how long the root rendering span should wait for the last component to render.
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:

```javascript
Sentry.init({
// ...
trackComponents: true,
timeout: 500,
});
```

The default is `2000`.

#### Alternative Configuration With `tracingOptions`
```javascript {8}
import * as Sentry from "@sentry/vue";

You can also group the component tracking options by using the optional `tracingOptions` property in `Sentry.init`:

```javascript
Sentry.init({
// ...
tracingOptions: {
trackComponents: true;
timeout: 500;
hooks: ['mount', 'update'];
}
})
integrations: [
Sentry.vueIntegration({
tracingOptions: {
trackComponents: true,
timeout: 500, // milliseconds
},
}),
],
});
```

Note that when you use this property there is no change in behaviour, as opposed to when you use the three top-level properties described above.

The default value for `tracingOptions` is `undefined`.
The default timeout is `2000` milliseconds.
5 changes: 1 addition & 4 deletions platform-includes/getting-started-config/javascript.vue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ To initialize Sentry in your Vue application, add the following code snippet to

### Vue 3


```javascript {filename:main.js} {"onboardingOptions": {"performance": "16, 19-26", "session-replay": "17, 27-31"}}
import { createApp } from "vue";
import { createRouter } from "vue-router";
Expand Down Expand Up @@ -43,7 +42,6 @@ app.mount("#app");

### Vue 2


```javascript {filename:main.js} {"onboardingOptions": {"performance": "15, 18-25", "session-replay": "16, 26-30"}}
import Vue from "vue";
import Router from "vue-router";
Expand Down Expand Up @@ -93,8 +91,7 @@ The SDK accepts a few Vue-specific `Sentry.init` configuration options:

- `attachProps` (defaults to `true`) - Includes all Vue components' props with the events.
- `logErrors` (defaults to `true`) - Decides whether SDK should call Vue's original `logError` function as well.
- `trackComponents` (defaults to `false`) - Track your app's components. Learn more about [component tracking](./features/component-tracking) and all its options.

- Check out how to [Track Vue Components](./features/component-tracking) for performance.

### Late-Defined Vue Apps

Expand Down
Loading