MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / TraceClass

Function TraceClass

packages/angular/src/tracing.ts:314–348  ·  view source on GitHub ↗
(options?: TraceClassOptions)

Source from the content-addressed store, hash-verified

312 * Decorator function that can be used to capture initialization lifecycle of the whole component.
313 */
314export function TraceClass(options?: TraceClassOptions): ClassDecorator {
315 let tracingSpan: Span;
316
317 /* eslint-disable @typescript-eslint/no-unsafe-member-access */
318 return target => {
319 const originalOnInit = target.prototype.ngOnInit;
320 target.prototype.ngOnInit = function (...args: unknown[]): ReturnType<typeof originalOnInit> {
321 tracingSpan = runOutsideAngular(() =>
322 startInactiveSpan({
323 onlyIfParent: true,
324 name: `<${options?.name || 'unnamed'}>`,
325 op: ANGULAR_INIT_OP,
326 attributes: {
327 [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_class_decorator',
328 },
329 }),
330 );
331
332 if (originalOnInit) {
333 return originalOnInit.apply(this, args);
334 }
335 };
336
337 const originalAfterViewInit = target.prototype.ngAfterViewInit;
338 target.prototype.ngAfterViewInit = function (...args: unknown[]): ReturnType<typeof originalAfterViewInit> {
339 if (tracingSpan) {
340 runOutsideAngular(() => tracingSpan.end());
341 }
342 if (originalAfterViewInit) {
343 return originalAfterViewInit.apply(this, args);
344 }
345 };
346 };
347 /* eslint-enable @typescript-eslint/no-unsafe-member-access */
348}
349
350interface TraceMethodOptions {
351 /**

Calls 4

runOutsideAngularFunction · 0.90
endMethod · 0.65
startInactiveSpanFunction · 0.50
applyMethod · 0.45

Tested by

no test coverage detected