diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts index a51191a443a3..2d8606480e50 100644 --- a/packages/angular/src/index.ts +++ b/packages/angular/src/index.ts @@ -5,8 +5,6 @@ export * from '@sentry/browser'; export { init } from './sdk'; export { createErrorHandler, SentryErrorHandler } from './errorhandler'; export { - // eslint-disable-next-line deprecation/deprecation - getActiveTransaction, browserTracingIntegration, TraceClassDecorator, TraceMethodDecorator, diff --git a/packages/angular/src/tracing.ts b/packages/angular/src/tracing.ts index 8b9b833ca3b8..8603dc550d9c 100644 --- a/packages/angular/src/tracing.ts +++ b/packages/angular/src/tracing.ts @@ -10,11 +10,15 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, browserTracingIntegration as originalBrowserTracingIntegration, + getActiveSpan, + getClient, getCurrentScope, + getRootSpan, + spanToJSON, startBrowserTracingNavigationSpan, + startInactiveSpan, } from '@sentry/browser'; -import { getActiveSpan, getClient, getRootSpan, spanToJSON, startInactiveSpan } from '@sentry/core'; -import type { Integration, Span, Transaction } from '@sentry/types'; +import type { Integration, Span } from '@sentry/types'; import { logger, stripUrlQueryAndFragment, timestampInSeconds } from '@sentry/utils'; import type { Observable } from 'rxjs'; import { Subscription } from 'rxjs'; @@ -59,16 +63,6 @@ export function _updateSpanAttributesForParametrizedUrl(route: string, span?: Sp } } -/** - * Grabs active transaction off scope. - * - * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. - */ -export function getActiveTransaction(): Transaction | undefined { - // eslint-disable-next-line deprecation/deprecation - return getCurrentScope().getTransaction(); -} - /** * Angular's Service responsible for hooking into Angular Router and tracking current navigation process. * Creates a new transaction for every route change and measures a duration of routing process. @@ -293,21 +287,19 @@ export function TraceClassDecorator(): ClassDecorator { let tracingSpan: Span; /* eslint-disable @typescript-eslint/no-unsafe-member-access */ - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type return target => { const originalOnInit = target.prototype.ngOnInit; // eslint-disable-next-line @typescript-eslint/no-explicit-any target.prototype.ngOnInit = function (...args: any[]): ReturnType { - // eslint-disable-next-line deprecation/deprecation - const activeTransaction = getActiveTransaction(); - if (activeTransaction) { - // eslint-disable-next-line deprecation/deprecation - tracingSpan = activeTransaction.startChild({ - name: `<${target.name}>`, - op: ANGULAR_INIT_OP, - origin: 'auto.ui.angular.trace_class_decorator', - }); - } + tracingSpan = startInactiveSpan({ + onlyIfParent: true, + name: `<${target.name}>`, + op: ANGULAR_INIT_OP, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_class_decorator', + }, + }); + if (originalOnInit) { return originalOnInit.apply(this, args); } @@ -331,24 +323,23 @@ export function TraceClassDecorator(): ClassDecorator { * Decorator function that can be used to capture a single lifecycle methods of the component. */ export function TraceMethodDecorator(): MethodDecorator { - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/ban-types + // eslint-disable-next-line @typescript-eslint/ban-types return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => { const originalMethod = descriptor.value; // eslint-disable-next-line @typescript-eslint/no-explicit-any descriptor.value = function (...args: any[]): ReturnType { const now = timestampInSeconds(); - // eslint-disable-next-line deprecation/deprecation - const activeTransaction = getActiveTransaction(); - if (activeTransaction) { - // eslint-disable-next-line deprecation/deprecation - activeTransaction.startChild({ - name: `<${target.constructor.name}>`, - endTimestamp: now, - op: `${ANGULAR_OP}.${String(propertyKey)}`, - origin: 'auto.ui.angular.trace_method_decorator', - startTimestamp: now, - }); - } + + startInactiveSpan({ + onlyIfParent: true, + name: `<${target.constructor.name}>`, + op: `${ANGULAR_OP}.${String(propertyKey)}`, + startTime: now, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_method_decorator', + }, + }).end(now); + if (originalMethod) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access return originalMethod.apply(this, args);