Skip to content
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

Streamline nuxt component tracking #11993

Merged
merged 1 commit into from
Dec 2, 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
111 changes: 52 additions & 59 deletions docs/platforms/javascript/guides/nuxt/features/component-tracking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,94 @@ description: "Learn how to monitor the rendering performance of your application
sidebar_order: 10
---

Sentry's Nuxt SDK has a component-tracking feature that lets you monitor the performance of your Vue components. 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 be impacting your app's performance.
Sentry's Nuxt 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

<Alert>

To set up component tracking, you need to first configure performance monitoring. For details on how to do this, check out our [Performance documentation](/platforms/javascript/guides/nuxt/performance/).
To set up component tracking, you need to first configure tracing. For details on how to do this, check out our [Tracing documentation](/platforms/javascript/guides/nuxt/performance/).

</Alert>

### Initial Application Load

By default, the Nuxt 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 [`trackComponents`](#trackcomponents) in your `Sentry.init` call. You can also optionally add [`hooks`](#hooks), and [`timeout`](#timeout).
To set it up, add the `vueIntegration` 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:

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

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

```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']`

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 default set of tracked hooks is `['activate', 'mount', 'update']`.

<Alert>

If you're using Vue 2, use `destroy` instead of `unmount`. But in Vue 3 `destroy` doesn't work because the names of the lifecycle hooks themselves [changed](https://v3-migration.vuejs.org/breaking-changes/#other-minor-changes).
The following hooks are available to track: `['activate', 'create', 'unmount', 'mount', 'update']`

</Alert>
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 default set of hooks is `['activate', 'mount', 'update']`.
#### Configure a Timeout for Component Tracking

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

You can specify how long the root rendering span should wait until the last component is rendered.
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 {8}
import * as Sentry from "@sentry/nuxt";

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

The default is `2000`.

#### Alternative Configuration With `tracingOptions`

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'];
}
})
```

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.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ By default, the Vue SDK tracks the rendering performance of your app (that is, i
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.
Set the `trackComponent` option to `true` to track all of your child components, or specify a list of individual comopnents you want to track:
Pass `true` to track all of your child components, or specify a list of individual comopnents you want to track:

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