From d57c269f25d4d091d0ad243c602d5b19da6d56f8 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 4 Apr 2022 11:47:40 -0400 Subject: [PATCH 1/2] feat(integrations): Remove @sentry/apm ref from vue --- packages/integrations/src/vue.ts | 58 +++++--------------------------- 1 file changed, 9 insertions(+), 49 deletions(-) diff --git a/packages/integrations/src/vue.ts b/packages/integrations/src/vue.ts index aefc8a89767b..628e153b7384 100644 --- a/packages/integrations/src/vue.ts +++ b/packages/integrations/src/vue.ts @@ -3,15 +3,6 @@ import { EventProcessor, Hub, Integration, IntegrationClass, Scope, Span, Transaction } from '@sentry/types'; import { basename, getGlobalObject, isDebugBuild, logger, timestampWithMs } from '@sentry/utils'; -/** - * Used to extract Tracing integration from the current client, - * without the need to import `Tracing` itself from the @sentry/apm package. - * @deprecated as @sentry/tracing should be used over @sentry/apm. - */ -const TRACING_GETTER = { - id: 'Tracing', -} as any as IntegrationClass; - /** * Used to extract BrowserTracing integration from @sentry/tracing */ @@ -148,7 +139,6 @@ export class Vue implements Integration { private readonly _componentsCache: { [key: string]: string } = {}; private _rootSpan?: Span; private _rootSpanTimer?: ReturnType; - private _tracingActivity?: number; /** * @inheritDoc @@ -258,30 +248,12 @@ export class Vue implements Integration { vm.$once(`hook:${hook}`, () => { // Create an activity on the first event call. There'll be no second call, as rootSpan will be in place, // thus new event handler won't be attached. - - // We do this whole dance with `TRACING_GETTER` to prevent `@sentry/apm` from becoming a peerDependency. - // We also need to ask for the `.constructor`, as `pushActivity` and `popActivity` are static, not instance methods. - /* eslint-disable @typescript-eslint/no-unsafe-member-access */ - // eslint-disable-next-line deprecation/deprecation - const tracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER); - if (tracingIntegration) { - this._tracingActivity = (tracingIntegration as any).constructor.pushActivity('Vue Application Render'); - const transaction = (tracingIntegration as any).constructor.getTransaction(); - if (transaction) { - this._rootSpan = transaction.startChild({ - description: 'Application Render', - op: VUE_OP, - }); - } - // Use functionality from @sentry/tracing - } else { - const activeTransaction = getActiveTransaction(getCurrentHub()); - if (activeTransaction) { - this._rootSpan = activeTransaction.startChild({ - description: 'Application Render', - op: VUE_OP, - }); - } + const activeTransaction = getActiveTransaction(getCurrentHub()); + if (activeTransaction) { + this._rootSpan = activeTransaction.startChild({ + description: 'Application Render', + op: VUE_OP, + }); } /* eslint-enable @typescript-eslint/no-unsafe-member-access */ }); @@ -347,24 +319,13 @@ export class Vue implements Integration { }; /** Finish top-level span and activity with a debounce configured using `timeout` option */ - private _finishRootSpan(timestamp: number, getCurrentHub: () => Hub): void { + private _finishRootSpan(timestamp: number, _getCurrentHub: () => Hub): void { if (this._rootSpanTimer) { clearTimeout(this._rootSpanTimer); } this._rootSpanTimer = setTimeout(() => { - if (this._tracingActivity) { - // We do this whole dance with `TRACING_GETTER` to prevent `@sentry/apm` from becoming a peerDependency. - // We also need to ask for the `.constructor`, as `pushActivity` and `popActivity` are static, not instance methods. - // eslint-disable-next-line deprecation/deprecation - const tracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER); - if (tracingIntegration) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - (tracingIntegration as any).constructor.popActivity(this._tracingActivity); - } - } - - // We should always finish the span, only should pop activity if using @sentry/apm + // We should always finish the span if (this._rootSpan) { this._rootSpan.finish(timestamp); } @@ -377,8 +338,7 @@ export class Vue implements Integration { this._options.Vue.mixin({ beforeCreate(this: ViewModel): void { - // eslint-disable-next-line deprecation/deprecation - if (getCurrentHub().getIntegration(TRACING_GETTER) || getCurrentHub().getIntegration(BROWSER_TRACING_GETTER)) { + if (getCurrentHub().getIntegration(BROWSER_TRACING_GETTER)) { // `this` points to currently rendered component applyTracingHooks(this, getCurrentHub); } else { From 7d18fc6011636f232221b415b588dcdf26529660 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 4 Apr 2022 11:49:36 -0400 Subject: [PATCH 2/2] feat(react): Remove @sentry/apm ref --- packages/react/src/profiler.tsx | 90 +++------------------------------ 1 file changed, 7 insertions(+), 83 deletions(-) diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index acf764347c69..c52d503eb92b 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { getCurrentHub, Hub } from '@sentry/browser'; -import { Integration, IntegrationClass, Span, Transaction } from '@sentry/types'; +import { Span, Transaction } from '@sentry/types'; import { timestampWithMs } from '@sentry/utils'; import hoistNonReactStatics from 'hoist-non-react-statics'; import * as React from 'react'; @@ -10,66 +10,6 @@ import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants'; export const UNKNOWN_COMPONENT = 'unknown'; -const TRACING_GETTER = ({ - id: 'Tracing', -} as any) as IntegrationClass; - -let globalTracingIntegration: Integration | null = null; -/** @deprecated remove when @sentry/apm no longer used */ -const getTracingIntegration = (): Integration | null => { - if (globalTracingIntegration) { - return globalTracingIntegration; - } - - globalTracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER); - return globalTracingIntegration; -}; - -/** - * pushActivity creates an new react activity. - * Is a no-op if Tracing integration is not valid - * @param name displayName of component that started activity - * @deprecated remove when @sentry/apm no longer used - */ -function pushActivity(name: string, op: string): number | null { - if (globalTracingIntegration === null) { - return null; - } - - return (globalTracingIntegration as any).constructor.pushActivity(name, { - description: `<${name}>`, - op, - }); -} - -/** - * popActivity removes a React activity. - * Is a no-op if Tracing integration is not valid. - * @param activity id of activity that is being popped - * @deprecated remove when @sentry/apm no longer used - */ -function popActivity(activity: number | null): void { - if (activity === null || globalTracingIntegration === null) { - return; - } - - (globalTracingIntegration as any).constructor.popActivity(activity); -} - -/** - * Obtain a span given an activity id. - * Is a no-op if Tracing integration is not valid. - * @param activity activity id associated with obtained span - * @deprecated remove when @sentry/apm no longer used - */ -function getActivitySpan(activity: number | null): Span | undefined { - if (activity === null || globalTracingIntegration === null) { - return undefined; - } - - return (globalTracingIntegration as any).constructor.getActivitySpan(activity) as Span | undefined; -} - export type ProfilerProps = { // The name of the component being profiled. name: string; @@ -95,9 +35,6 @@ class Profiler extends React.Component { */ protected _mountSpan: Span | undefined = undefined; - // The activity representing how long it takes to mount a component. - private _mountActivity: number | null = null; - // eslint-disable-next-line @typescript-eslint/member-ordering public static defaultProps: Partial = { disabled: false, @@ -113,19 +50,12 @@ class Profiler extends React.Component { return; } - // If they are using @sentry/apm, we need to push/pop activities - // eslint-disable-next-line deprecation/deprecation - if (getTracingIntegration()) { - // eslint-disable-next-line deprecation/deprecation - this._mountActivity = pushActivity(name, REACT_MOUNT_OP); - } else { - const activeTransaction = getActiveTransaction(); - if (activeTransaction) { - this._mountSpan = activeTransaction.startChild({ - description: `<${name}>`, - op: REACT_MOUNT_OP, - }); - } + const activeTransaction = getActiveTransaction(); + if (activeTransaction) { + this._mountSpan = activeTransaction.startChild({ + description: `<${name}>`, + op: REACT_MOUNT_OP, + }); } } @@ -133,12 +63,6 @@ class Profiler extends React.Component { public componentDidMount(): void { if (this._mountSpan) { this._mountSpan.finish(); - } else { - // eslint-disable-next-line deprecation/deprecation - this._mountSpan = getActivitySpan(this._mountActivity); - // eslint-disable-next-line deprecation/deprecation - popActivity(this._mountActivity); - this._mountActivity = null; } }