Skip to content

Commit

Permalink
feat(integrations): Deprecate pluggable integration classes (#10211)
Browse files Browse the repository at this point in the history
Instead, users should import & use the integration functions.
  • Loading branch information
mydea authored Jan 17, 2024
1 parent 11a8afe commit 9dbe87e
Show file tree
Hide file tree
Showing 22 changed files with 191 additions and 93 deletions.
18 changes: 15 additions & 3 deletions packages/integrations/src/captureconsole.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { captureException, captureMessage, convertIntegrationFnToClass, getClient, withScope } from '@sentry/core';
import {
captureException,
captureMessage,
convertIntegrationFnToClass,
defineIntegration,
getClient,
withScope,
} from '@sentry/core';
import type { CaptureContext, Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import {
CONSOLE_LEVELS,
Expand All @@ -15,7 +22,7 @@ interface CaptureConsoleOptions {

const INTEGRATION_NAME = 'CaptureConsole';

const captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {
const _captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {
const levels = options.levels || CONSOLE_LEVELS;

return {
Expand All @@ -38,7 +45,12 @@ const captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {
};
}) satisfies IntegrationFn;

/** Send Console API calls as Sentry Events */
export const captureConsoleIntegration = defineIntegration(_captureConsoleIntegration);

/**
* Send Console API calls as Sentry Events.
* @deprecated Use `captureConsoleIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const CaptureConsole = convertIntegrationFnToClass(
INTEGRATION_NAME,
Expand Down
8 changes: 6 additions & 2 deletions packages/integrations/src/contextlines.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
import { GLOBAL_OBJ, addContextToFrame, stripUrlQueryAndFragment } from '@sentry/utils';

Expand All @@ -18,7 +18,7 @@ interface ContextLinesOptions {
frameContextLines?: number;
}

const contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
const _contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
const contextLines = options.frameContextLines != null ? options.frameContextLines : DEFAULT_LINES_OF_CONTEXT;

return {
Expand All @@ -31,6 +31,8 @@ const contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
};
}) satisfies IntegrationFn;

export const contextLinesIntegration = defineIntegration(_contextLinesIntegration);

/**
* Collects source context lines around the lines of stackframes pointing to JS embedded in
* the current page's HTML.
Expand All @@ -41,6 +43,8 @@ const contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
*
* Use this integration if you have inline JS code in HTML pages that can't be accessed
* by our backend (e.g. due to a login-protected page).
*
* @deprecated Use `contextLinesIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const ContextLines = convertIntegrationFnToClass(INTEGRATION_NAME, contextLinesIntegration) as IntegrationClass<
Expand Down
10 changes: 7 additions & 3 deletions packages/integrations/src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';

Expand All @@ -11,7 +11,7 @@ interface DebugOptions {
debugger?: boolean;
}

const debugIntegration = ((options: DebugOptions = {}) => {
const _debugIntegration = ((options: DebugOptions = {}) => {
const _options = {
debugger: false,
stringify: false,
Expand Down Expand Up @@ -53,9 +53,13 @@ const debugIntegration = ((options: DebugOptions = {}) => {
};
}) satisfies IntegrationFn;

export const debugIntegration = defineIntegration(_debugIntegration);

/**
* Integration to debug sent Sentry events.
* This integration should not be used in production
* This integration should not be used in production.
*
* @deprecated Use `debugIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const Debug = convertIntegrationFnToClass(INTEGRATION_NAME, debugIntegration) as IntegrationClass<
Expand Down
11 changes: 8 additions & 3 deletions packages/integrations/src/dedupe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Exception, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
import { logger } from '@sentry/utils';

import { DEBUG_BUILD } from './debug-build';

const INTEGRATION_NAME = 'Dedupe';

const dedupeIntegration = (() => {
const _dedupeIntegration = (() => {
let previousEvent: Event | undefined;

return {
Expand All @@ -33,7 +33,12 @@ const dedupeIntegration = (() => {
};
}) satisfies IntegrationFn;

/** Deduplication filter */
export const dedupeIntegration = defineIntegration(_dedupeIntegration);

/**
* Deduplication filter.
* @deprecated Use `dedupeIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const Dedupe = convertIntegrationFnToClass(INTEGRATION_NAME, dedupeIntegration) as IntegrationClass<
Integration & { processEvent: (event: Event) => Event }
Expand Down
11 changes: 8 additions & 3 deletions packages/integrations/src/extraerrordata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type {
Contexts,
Event,
Expand Down Expand Up @@ -28,7 +28,7 @@ interface ExtraErrorDataOptions {
captureErrorCause: boolean;
}

const extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {}) => {
const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {}) => {
const depth = options.depth || 3;

// TODO(v8): Flip the default for this option to true
Expand All @@ -44,7 +44,12 @@ const extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {}
};
}) satisfies IntegrationFn;

/** Extract additional data for from original exceptions. */
export const extraErrorDataIntegration = defineIntegration(_extraErrorDataIntegration);

/**
* Extract additional data for from original exceptions.
* @deprecated Use `extraErrorDataIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const ExtraErrorData = convertIntegrationFnToClass(
INTEGRATION_NAME,
Expand Down
17 changes: 14 additions & 3 deletions packages/integrations/src/httpclient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { captureEvent, convertIntegrationFnToClass, getClient, isSentryRequestUrl } from '@sentry/core';
import {
captureEvent,
convertIntegrationFnToClass,
defineIntegration,
getClient,
isSentryRequestUrl,
} from '@sentry/core';
import type {
Client,
Event as SentryEvent,
Expand Down Expand Up @@ -45,7 +51,7 @@ interface HttpClientOptions {
failedRequestTargets: HttpRequestTarget[];
}

const httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
const _httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
const _options: HttpClientOptions = {
failedRequestStatusCodes: [[500, 599]],
failedRequestTargets: [/.*/],
Expand All @@ -63,7 +69,12 @@ const httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
};
}) satisfies IntegrationFn;

/** HTTPClient integration creates events for failed client side HTTP requests. */
export const httpClientIntegration = defineIntegration(_httpClientIntegration);

/**
* Create events for failed client side HTTP requests.
* @deprecated Use `httpClientIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const HttpClient = convertIntegrationFnToClass(INTEGRATION_NAME, httpClientIntegration) as IntegrationClass<
Integration & { setup: (client: Client) => void }
Expand Down
21 changes: 10 additions & 11 deletions packages/integrations/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
export { CaptureConsole } from './captureconsole';
export { Debug } from './debug';
export { Dedupe } from './dedupe';
export { ExtraErrorData } from './extraerrordata';
// eslint-disable-next-line deprecation/deprecation
/* eslint-disable deprecation/deprecation */
export { CaptureConsole, captureConsoleIntegration } from './captureconsole';
export { Debug, debugIntegration } from './debug';
export { Dedupe, dedupeIntegration } from './dedupe';
export { ExtraErrorData, extraErrorDataIntegration } from './extraerrordata';
export { Offline } from './offline';
export { ReportingObserver } from './reportingobserver';
export { RewriteFrames } from './rewriteframes';
export { SessionTiming } from './sessiontiming';
// eslint-disable-next-line deprecation/deprecation
export { ReportingObserver, reportingObserverIntegration } from './reportingobserver';
export { RewriteFrames, rewriteFramesIntegration } from './rewriteframes';
export { SessionTiming, sessionTimingIntegration } from './sessiontiming';
export { Transaction } from './transaction';
export { HttpClient } from './httpclient';
export { ContextLines } from './contextlines';
export { HttpClient, httpClientIntegration } from './httpclient';
export { ContextLines, contextLinesIntegration } from './contextlines';
11 changes: 8 additions & 3 deletions packages/integrations/src/reportingobserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureMessage, convertIntegrationFnToClass, getClient, withScope } from '@sentry/core';
import { captureMessage, convertIntegrationFnToClass, defineIntegration, getClient, withScope } from '@sentry/core';
import type { Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import { GLOBAL_OBJ, supportsReportingObserver } from '@sentry/utils';

Expand Down Expand Up @@ -48,7 +48,7 @@ interface ReportingObserverOptions {

const SETUP_CLIENTS = new WeakMap<Client, boolean>();

const reportingObserverIntegration = ((options: ReportingObserverOptions = {}) => {
const _reportingObserverIntegration = ((options: ReportingObserverOptions = {}) => {
const types = options.types || ['crash', 'deprecation', 'intervention'];

/** Handler for the reporting observer. */
Expand Down Expand Up @@ -115,7 +115,12 @@ const reportingObserverIntegration = ((options: ReportingObserverOptions = {}) =
};
}) satisfies IntegrationFn;

/** Reporting API integration - https://w3c.github.io/reporting/ */
export const reportingObserverIntegration = defineIntegration(_reportingObserverIntegration);

/**
* Reporting API integration - https://w3c.github.io/reporting/
* @deprecated Use `reportingObserverIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const ReportingObserver = convertIntegrationFnToClass(
INTEGRATION_NAME,
Expand Down
11 changes: 8 additions & 3 deletions packages/integrations/src/rewriteframes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame, Stacktrace } from '@sentry/types';
import { basename, relative } from '@sentry/utils';

Expand All @@ -12,7 +12,7 @@ interface RewriteFramesOptions {
iteratee?: StackFrameIteratee;
}

const rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {
const _rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {
const root = options.root;
const prefix = options.prefix || 'app:///';

Expand Down Expand Up @@ -85,7 +85,12 @@ const rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {
};
}) satisfies IntegrationFn;

/** Rewrite event frames paths */
export const rewriteFramesIntegration = defineIntegration(_rewriteFramesIntegration);

/**
* Rewrite event frames paths.
* @deprecated Use `rewriteFramesIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const RewriteFrames = convertIntegrationFnToClass(
INTEGRATION_NAME,
Expand Down
11 changes: 8 additions & 3 deletions packages/integrations/src/sessiontiming.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';

const INTEGRATION_NAME = 'SessionTiming';

const sessionTimingIntegration = (() => {
const _sessionTimingIntegration = (() => {
const startTime = Date.now();

return {
Expand All @@ -26,7 +26,12 @@ const sessionTimingIntegration = (() => {
};
}) satisfies IntegrationFn;

/** This function adds duration since Sentry was initialized till the time event was sent */
export const sessionTimingIntegration = defineIntegration(_sessionTimingIntegration);

/**
* This function adds duration since Sentry was initialized till the time event was sent.
* @deprecated Use `sessionTimingIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const SessionTiming = convertIntegrationFnToClass(
INTEGRATION_NAME,
Expand Down
Loading

0 comments on commit 9dbe87e

Please sign in to comment.