Skip to content

Commit 62ad0f3

Browse files
authored
fix(angular): Set unknown component name default in TraceDirective (#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> ```
1 parent 1a64b60 commit 62ad0f3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/angular/src/tracing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const UNKNOWN_COMPONENT = 'unknown';
159159
*/
160160
@Directive({ selector: '[trace]' })
161161
export class TraceDirective implements OnInit, AfterViewInit {
162-
@Input('trace') public componentName: string = UNKNOWN_COMPONENT;
162+
@Input('trace') public componentName?: string;
163163

164164
private _tracingSpan?: Span;
165165

@@ -168,6 +168,10 @@ export class TraceDirective implements OnInit, AfterViewInit {
168168
* @inheritdoc
169169
*/
170170
public ngOnInit(): void {
171+
if (!this.componentName) {
172+
this.componentName = UNKNOWN_COMPONENT;
173+
}
174+
171175
const activeTransaction = getActiveTransaction();
172176
if (activeTransaction) {
173177
this._tracingSpan = activeTransaction.startChild({

0 commit comments

Comments
 (0)