Skip to content

[v7] feat: Remove references to @sentry/apm #4845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2022
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
58 changes: 9 additions & 49 deletions packages/integrations/src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integration>;

/**
* Used to extract BrowserTracing integration from @sentry/tracing
*/
Expand Down Expand Up @@ -148,7 +139,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 @@ -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 */
});
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
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