Skip to content

Commit

Permalink
fix(angular): Set unknown component name default in TraceDirective (#…
Browse files Browse the repository at this point in the history
…6222)

Fix a bug in the Angular SDK's `TraceDirective` where previously, the fallback `UNKNOWN_COMPONENT` name wasn't correctly applied to the span description if users didn't specify a manual value for the directive:

```html
<!-- this adds <standalone1> as a span description  -->
<app-my-component trace="standalone1"></app-my-component>

<!-- this used to add <> as a span description  -->
<!-- With this fix, we now get <unknown> as a span description  -->
<app-my-component trace></app-my-component>
```
  • Loading branch information
Lms24 committed Nov 17, 2022
1 parent 1a64b60 commit 62ad0f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/angular/src/tracing.ts
Expand Up @@ -159,7 +159,7 @@ const UNKNOWN_COMPONENT = 'unknown';
*/
@Directive({ selector: '[trace]' })
export class TraceDirective implements OnInit, AfterViewInit {
@Input('trace') public componentName: string = UNKNOWN_COMPONENT;
@Input('trace') public componentName?: string;

private _tracingSpan?: Span;

Expand All @@ -168,6 +168,10 @@ export class TraceDirective implements OnInit, AfterViewInit {
* @inheritdoc
*/
public ngOnInit(): void {
if (!this.componentName) {
this.componentName = UNKNOWN_COMPONENT;
}

const activeTransaction = getActiveTransaction();
if (activeTransaction) {
this._tracingSpan = activeTransaction.startChild({
Expand Down

0 comments on commit 62ad0f3

Please sign in to comment.