Skip to content

Commit

Permalink
[v7] feat: Remove references to @sentry/apm (#4845)
Browse files Browse the repository at this point in the history
Removes all references to `@sentry/apm`, a deprecated package we do not use anymore.
  • Loading branch information
AbhiPrasad authored and lobsterkatie committed Apr 7, 2022
1 parent 4e722eb commit 378a6cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 132 deletions.
58 changes: 9 additions & 49 deletions packages/integrations/src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import { basename, getGlobalObject, logger, timestampWithMs } from '@sentry/util

import { IS_DEBUG_BUILD } from './flags';

/**
* 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<Integration>;

/**
* Used to extract BrowserTracing integration from @sentry/tracing
*/
Expand Down Expand Up @@ -150,7 +141,6 @@ export class Vue implements Integration {
private readonly _componentsCache: { [key: string]: string } = {};
private _rootSpan?: Span;
private _rootSpanTimer?: ReturnType<typeof setTimeout>;
private _tracingActivity?: number;

/**
* @inheritDoc
Expand Down Expand Up @@ -260,30 +250,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 */
});
Expand Down Expand Up @@ -349,24 +321,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);
}
Expand All @@ -379,8 +340,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 {
Expand Down
90 changes: 7 additions & 83 deletions packages/react/src/profiler.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Integration>;

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;
Expand All @@ -95,9 +35,6 @@ class Profiler extends React.Component<ProfilerProps> {
*/
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<ProfilerProps> = {
disabled: false,
Expand All @@ -113,32 +50,19 @@ class Profiler extends React.Component<ProfilerProps> {
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,
});
}
}

// If a component mounted, we can finish the mount activity.
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;
}
}

Expand Down

0 comments on commit 378a6cd

Please sign in to comment.