Skip to content

Commit ef41fda

Browse files
Lms24imatwawana
andauthored
fix(angular): mention TraceDirective bug and workaround in Angular SDK (#4780)
* fix(angular): mention `TraceDirective` bug and workaround in Angular SDK Add a warning alert to `tracehelpers.mdx` in the Angular SDK guide to make users aware that the usage of `TraceDirective` will most likely cause a compiler error on their end. The alert links to the original issue and our intended fix which will ship with the v7 major of the JS/Angular SDK. Fix suboptimal usage instruction of `TraceDirective`: Instead of declaring `TraceDirective` in the users' Angular module(s), `TraceModule` (which wraps the directive) should in fact be imported in the module(s). This conforms to the way how Angular component libraries should be used. * Update src/platforms/javascript/guides/angular/components/tracehelpers.mdx Co-authored-by: Isabel <[email protected]> * Update src/platforms/javascript/guides/angular/components/tracehelpers.mdx Co-authored-by: Isabel <[email protected]> * Update src/platforms/javascript/guides/angular/components/tracehelpers.mdx Co-authored-by: Isabel <[email protected]> Co-authored-by: Isabel <[email protected]>
1 parent 94ceaea commit ef41fda

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

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

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,7 @@ title: Track Angular Components
44

55
To track Angular components as part of your transactions, use any of these three options:
66

7-
1. `TraceDirective` to track a duration between `OnInit` and `AfterViewInit` lifecycle hooks in template:
8-
9-
```javascript
10-
import * as Sentry from "@sentry/angular";
11-
12-
@NgModule({
13-
// ...
14-
declarations: [Sentry.TraceDirective],
15-
// ...
16-
})
17-
export class AppModule {}
18-
```
19-
20-
Then, inside your components template, (remember that the directive name attribute is required):
21-
22-
```html
23-
<app-header [trace]="'header'"></app-header>
24-
<articles-list [trace]="'articles-list'"></articles-list>
25-
<app-footer [trace]="'footer'"></app-footer>
26-
```
27-
28-
2. `TraceClassDecorator` tracks a duration between `OnInit` and `AfterViewInit` lifecycle hooks in components:
7+
1. `TraceClassDecorator` tracks a duration between `OnInit` and `AfterViewInit` lifecycle hooks in components:
298

309
```javascript
3110
import { Component } from "@angular/core";
@@ -41,7 +20,7 @@ export class HeaderComponent {
4120
}
4221
```
4322

44-
3. `TraceMethodDecorator` tracks a specific lifecycle hooks as point-in-time spans in components:
23+
2. `TraceMethodDecorator` tracks a specific lifecycle hooks as point-in-time spans in components:
4524

4625
```javascript
4726
import { Component, OnInit } from "@angular/core";
@@ -87,3 +66,39 @@ platformBrowserDynamic()
8766
}
8867
})
8968
```
69+
70+
3. `TraceDirective` tracks a duration between `OnInit` and `AfterViewInit` lifecycle hooks in template:
71+
72+
<Alert level="warning" title="Important">
73+
74+
Using `TraceDirective` or `TraceModule` currently causes a compiler error at application compile
75+
time of your Angular application if AOT compilation is enabled in your application config (which it is by default).
76+
This is a [known limitation](https://github.com/getsentry/sentry-javascript/issues/3282) of our current
77+
Angular SDK (v6.*) and it will be [adressed and fixed](https://github.com/getsentry/sentry-javascript/issues/4644)
78+
in our next major Angular SDK release (v7).
79+
In the meantime, please use options 1 (`TraceClassDecorator`) and 2 (`TraceMethodDecorator`)
80+
above to track your Angular components.
81+
82+
</Alert>
83+
84+
Import `TraceModule` either globally in your application's `app.module.ts` file or locally in the module(s)
85+
you want to track your components:
86+
87+
```javascript
88+
import * as Sentry from "@sentry/angular";
89+
90+
@NgModule({
91+
// ...
92+
imports: [Sentry.TraceModule],
93+
// ...
94+
})
95+
export class AppModule {}
96+
```
97+
98+
Then, inside your components template, (remember that the directive name attribute is required):
99+
100+
```html
101+
<app-header [trace]="'header'"></app-header>
102+
<articles-list [trace]="'articles-list'"></articles-list>
103+
<app-footer [trace]="'footer'"></app-footer>
104+
```

0 commit comments

Comments
 (0)