Skip to content

Commit 9345e19

Browse files
Lms24imatwawana
andauthored
ref: Improve JS SDK Component Tracking Documentation (#5619)
Make structural, naming and content changes to the documentation of a feature we support in four JS framework SDKs - component tracking. Previously, this documentation differed drastically between these four SDKs. Not only did the location differ, but also, how we called the feature. With this patch, we're introducing one name that describes this feature, while we still find a balance between "component tracking" and however the feature is called in the SDK's code (e.g. "trace helpers" in Angular or "Profiler" in React). Impacted SDKs: Angular, React, Vue, Svelte As of this patch, we make the following changes: **All SDKs** * Adjusted the naming and location of the documentation. In the menu on the left, it is now located under "<Framework> Features" -> "Component Tracking" * Added a sentence in all "<framwork> Features" index pages explaining that these features are specifically built for the respective framework. For example, in React we don't only have component tracking as such a feature but also the Sentry error boundary. * Added a small paragraph on top of the component tracking page, explaining the feature and why it's helpful * Mentioned the names of the spans that this feature adds to the transactions so that users are aware of what it is actually doing. The React docs were already doing this and I thought this would be valuable information for every SDK. **Angular**: * Rephrased some paragraphs and sentences that were previously confusing * Added sub-headings for each utility (previously it was a list) * Added an "Advanced" usage section, explaining that the utilities can be used together * Adjusted the code examples and corrected some minor mistakes **Vue**: The Vue SDK documentation didn't have a proper page for component tracking previously. Instead it was spread across three pages. * Moved component tracking documentation from the "Vue Router Integration" to the new component tracking page * Adjusted this documentation by * Removing unnecessary technical details * Better explaining each of the three options * Removing lifecycle hooks that weren't even supported by the SDK * Since component tracking was mentioned in two other pages (Getting started and Performance Setup), I decided to shorten the description in the respective places to only leave the gist there. In both places, I added links to the component tracking page for more details. * Left the part that is actually about the Vue router on the "Vue Router Integration" page. * I'm not too happy with this, because technically speaking we don't have a Vue router integration but an _instrumentation_ but we do the same thing in the React SDK. In both cases, the pages actually contain relevant information. So we can leave it for now as is and revisit this if it comes up. Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
1 parent 4fcb302 commit 9345e19

File tree

19 files changed

+338
-271
lines changed

19 files changed

+338
-271
lines changed

src/platform-includes/getting-started-config/javascript.react.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Once this is done, all unhandled exceptions are automatically captured by Sentry
2424

2525
### Add Error Boundary
2626

27-
If you're using React 16 or above, you can use the [Error Boundary](components/errorboundary/) component to automatically send Javascript errors from inside a component tree to Sentry, and set a fallback UI.
27+
If you're using React 16 or above, you can use the [Error Boundary](features/error-boundary/) component to automatically send Javascript errors from inside a component tree to Sentry, and set a fallback UI.
2828

2929
### Set Up React Router
3030

src/platform-includes/getting-started-config/javascript.vue.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ The SDK accepts a few different configuration options that let you change its be
107107

108108
- `attachProps` (defaults to `true`) - Includes all Vue components' props with the events.
109109
- `logErrors` (defaults to `false`) - Decides whether SDK should call Vue's original `logError` function as well.
110-
- `trackComponents` (defaults to `false`) - Decides whether to track components by hooking into its lifecycle methods. Can be set to either `boolean`, to enable/disable tracking for all of them, or to an array of specific component names (case-sensitive).
111-
- `timeout` (defaults to `2000`) - Time in milliseconds dictating how long to wait until the tracked root activity is marked as finished and sent off to Sentry.
112-
- `hooks` (defaults to `['activate', 'mount', 'update']`) - List of hooks to keep track of during component lifecycle `'activate' | 'create' | 'destroy' | 'mount' | 'unmount' | 'update'`.
110+
- `trackComponents` (defaults to `false`) - Track your app's components. Learn more about [component tracking](./features/component-tracking) and all its options.
113111

114112
<Note>
115113

src/platform-includes/performance/configure-sample-rate/javascript.vue.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Sentry.init({
1515

1616
// This enables automatic instrumentation (highly recommended), but is not
1717
// necessary for purely manual usage
18-
integrations: [new BrowserTracing],
18+
integrations: [new BrowserTracing()],
1919

2020
// To set a uniform sample rate
2121
tracesSampleRate: 0.2
@@ -43,11 +43,7 @@ Sentry.init({
4343

4444
## Configure Tracing Instrumentation
4545

46-
If you want to track child components or use additional hooks to see more details about the rendering process, you can configure the SDK using options below. Captured data will be then stored as spans and attached to the currently active transaction on the scope:
47-
48-
- `trackComponents` (defaults to `false`) - Decides whether to track components by hooking into its lifecycle methods. Can be set to either `boolean`, to enable/disable tracking for all of them, or to an array of specific component names (case-sensitive).
49-
- `timeout` (defaults to `2000`) - Time in milliseconds dictating how long to wait until the tracked root activity is marked as finished and sent off to Sentry.
50-
- `hooks` (defaults to `['activate', 'mount', 'update']`) - List of hooks to keep track of during component lifecycle `'activate' | 'create' | 'destroy' | 'mount' | 'unmount' | 'update'`.
46+
If you want to track child components, you can configure the SDK using additional options as shown below. Captured data will be then stored as spans and attached to the currently active transaction:
5147

5248
```javascript
5349
Sentry.init({
@@ -57,3 +53,5 @@ Sentry.init({
5753
hooks: ["create", "mount"],
5854
});
5955
```
56+
57+
Learn more about [Vue component tracking](../features/component-tracking).

src/platforms/common/performance/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ import * as Sentry from "@sentry/react";
136136
export default Sentry.withProfiler(App);
137137
```
138138

139-
Learn more about using and customizing the React Profiler in [Profiler](/platforms/javascript/guides/react/components/profiler/).
139+
Learn more about using and customizing the React Profiler in [React Component Tracking](/platforms/javascript/guides/react/features/component-tracking/).
140140

141141
## React Router
142142

src/platforms/javascript/guides/angular/components/index.mdx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/platforms/javascript/guides/angular/components/tracehelpers.mdx

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
title: Track Angular Components
3+
description: "Learn how Sentry's Angular SDK allows you to monitor the rendering performance of your application and its components."
4+
---
5+
6+
Sentry's Angular SDK offers a feature to monitor the performance of your Angular components: component tracking. Enabling this feature provides you with spans in your transactions that show the initialization and update cycles of your Angular components. 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.
7+
8+
<Alert>
9+
10+
To set up component tracking, you need to configure performance monitoring. For details on how to do this, check out our [Performance documentation](/platforms/javascript/guides/angular/performance/).
11+
12+
</Alert>
13+
14+
To track your components as part of your transactions, use any (or a combination) of the following options.
15+
16+
## Using `TraceDirective`
17+
18+
`TraceDirective` tracks a duration between the `OnInit` and `AfterViewInit` lifecycle hooks in your component template. It adds spans called **`ui.angular.init`** to the currently active transaction that allows you to track specific individual instances of your components. If you want to track all instances instead, use [`TraceClassDecorator`](#using-traceclassdecorator).
19+
20+
Import `TraceModule` either globally in your application's `app.module.ts` file or in the module(s) in which
21+
you want to track your components:
22+
23+
```typescript {filename:app.module.ts}
24+
import * as Sentry from "@sentry/angular";
25+
26+
@NgModule({
27+
// ...
28+
imports: [Sentry.TraceModule],
29+
// ...
30+
})
31+
export class AppModule {}
32+
```
33+
34+
Then, in your component's template, add the directive to all components you want to track. Remember to give the `trace` attribute a name, which will be shown in the span's description:
35+
36+
```html {filename:app.component.ts}
37+
<app-header [trace]="'header'"></app-header>
38+
<articles-list [trace]="'articles-list'"></articles-list>
39+
<app-footer [trace]="'footer'"></app-footer>
40+
```
41+
42+
<Alert level="info" title="Compatibility">
43+
44+
If you're using version 6 of the Angular SDK, using `TraceDirective` or `TraceModule` causes a
45+
compiler error at application compile time of your Angular application. This is a [known issue](https://github.com/getsentry/sentry-javascript/issues/3282)
46+
of our Angular SDK v6 and it was [fixed](https://github.com/getsentry/sentry-javascript/issues/4644)
47+
in version 7. We recommend upgrading to the latest Angular SDK version.
48+
Otherwise, please use the other options (`TraceClassDecorator` and `TraceMethodDecorator`)
49+
below to track your Angular components.
50+
51+
</Alert>
52+
53+
## Using `TraceClassDecorator`
54+
55+
`TraceClassDecorator` tracks the duration between the `OnInit` and `AfterViewInit` lifecycle hooks in components. It adds spans called **`ui.angular.init`** to the currently active transaction. In contrast to [`TraceDirective`](#using-tracedirective), `TraceClassDecorator` tracks all instances of the component(s) you add it to, creating spans for each component instance.
56+
57+
Just add `TraceClassDecorator` to the components you want to track:
58+
59+
```typescript {filename:header.component.ts}
60+
import { Component } from "@angular/core";
61+
import * as Sentry from "@sentry/angular";
62+
63+
@Component({
64+
selector: "app-header",
65+
templateUrl: "./header.component.html",
66+
})
67+
@Sentry.TraceClassDecorator()
68+
export class HeaderComponent {
69+
// ...
70+
}
71+
```
72+
73+
## Using `TraceMethodDecorator`
74+
75+
`TraceMethodDecorator` tracks specific component lifecycle hooks as point-in-time spans. The added spans are called **`ui.angular.[methodname]`** (like, `ui.angular.ngOnChanges`). For example, you can use this decorator to track how often component changes are detected during an ongoing transaction:
76+
77+
```typescript {filename:login.component.ts}
78+
import { Component, OnInit } from "@angular/core";
79+
import * as Sentry from "@sentry/angular";
80+
81+
@Component({
82+
selector: "app-login",
83+
templateUrl: "./login.component.html",
84+
})
85+
export class LoginComponent implements OnChanges {
86+
@Sentry.TraceMethodDecorator()
87+
ngOnChanges(changes: SimpleChanges) {}
88+
}
89+
```
90+
91+
## Advanced Usage
92+
93+
You can combine our tracking utilities and track the bootstrapping duration of your app.
94+
95+
### Combining Component Tracking Utilities
96+
97+
To get the best insights into your components' performance, you can combine `TraceDirective`, `TraceClassDecorator`, and `TraceMethodDecorator`. This allows you to track component initialization durations as well as arbitrary lifecycle events, such as change and destroy events:
98+
99+
```typescript {filename:user-card.component.ts}
100+
import { Component, OnInit } from "@angular/core";
101+
import * as Sentry from "@sentry/angular";
102+
103+
@Component({
104+
selector: "app-user-card",
105+
templateUrl: "./user-card.component.html",
106+
})
107+
@Sentry.TraceClassDecorator()
108+
export class UserCardComponent implements OnChanges, OnDestroy {
109+
@Sentry.TraceMethodDecorator()
110+
ngOnChanges(changes: SimpleChanges) {}
111+
112+
@Sentry.TraceMethodDecorator()
113+
ngOnDestroy() {}
114+
}
115+
```
116+
117+
User `TraceDirective` if you only want to track components in certain instances or locations:
118+
119+
```html {user-card.component.html}
120+
<div>
121+
<app-icon trace="user-icon">user</app-icon>
122+
<label>{{ user.name }}</label>
123+
<!--...-->
124+
<app-button trace="save-user">Save</app-button>
125+
</div>
126+
```
127+
128+
### Track Angular Bootstrapping
129+
130+
You can add your own custom spans by attaching them to the currently active transaction using the `getActiveTransaction`
131+
helper. For example, you can track the duration of the Angular bootstrapping process to find out how long your app takes to bootstrap on your users' devices:
132+
133+
```javascript
134+
import { enableProdMode } from "@angular/core";
135+
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
136+
import * as Sentry from "@sentry/angular";
137+
138+
import { AppModule } from "./app/app.module";
139+
140+
// ...
141+
142+
const activeTransaction = Sentry.getActiveTransaction();
143+
const bootstrapSpan =
144+
activeTransaction &&
145+
activeTransaction.startChild({
146+
description: "platform-browser-dynamic",
147+
op: "ui.angular.bootstrap",
148+
});
149+
150+
platformBrowserDynamic()
151+
.bootstrapModule(AppModule)
152+
.then(() => console.log(`Bootstrap success`))
153+
.catch(err => console.error(err))
154+
.finally(() => {
155+
if (bootstrapSpan) {
156+
bootstrapSpan.finish();
157+
}
158+
});
159+
```
160+
161+
Learn more about [custom instrumentation](../../performance/instrumentation/custom-instrumentation/).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Angular Features
3+
description: "Learn how Sentry's Angular SDK exposes features for first class integration with Angular."
4+
excerpt: ""
5+
---
6+
7+
The Sentry Angular SDK offers Angular-specific features for first class integration with the framework.
8+
9+
<PageGrid />

src/platforms/javascript/guides/react/components/index.mdx

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/platforms/javascript/guides/react/components/profiler.mdx renamed to src/platforms/javascript/guides/react/features/component-tracking.mdx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
---
2-
title: React Profiler
2+
title: Track React Components
33
excerpt: ""
4-
description: "Learn how Sentry's React SDK exports a `withProfiler` higher-order component that attaches React related spans to the current active transaction on the scope."
4+
description: "Learn how Sentry's React SDK allows you to monitor the rendering performance of your application and its components."
55
---
66

7-
`@sentry/react` exports a `withProfiler` higher-order component that attaches React related spans to the current active transaction on the scope.
7+
Sentry's React SDK offers a feature to monitor the performance of your React components: component tracking. The SDK exports a `withProfiler` higher-order component that attaches React related spans to the current active transaction on the scope. This allows you to get a drilled-down view into how your components are behaving so you can do things like identify slow mounts or frequent updates, which might have an impact on your app's performance.
88

9-
In the example below, the `withProfiler` higher-order component is used to instrument an App component.
9+
<Alert>
10+
11+
To set up component tracking, you need to configure performance monitoring. For details on how to do this, check out our [Performance documentation](/platforms/javascript/guides/react/performance/).
12+
13+
</Alert>
14+
15+
In the example below, the `withProfiler` higher-order component is used to instrument an app component.
1016

1117
```javascript
1218
import React from "react";
@@ -69,4 +75,4 @@ export default Sentry.withProfiler(App, { name: "CustomAppName" });
6975
## Next Steps:
7076

7177
- [Return to **Getting Started**](../../)
72-
- [Return to the main components page](../)
78+
- [Return to **React Features**](../)

0 commit comments

Comments
 (0)