Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 27 additions & 36 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<typeof originalOnInit> {
// 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);
}
Expand All @@ -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<typeof originalMethod> {
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);
Expand Down