Skip to content

Commit 9dbe87e

Browse files
authored
feat(integrations): Deprecate pluggable integration classes (#10211)
Instead, users should import & use the integration functions.
1 parent 11a8afe commit 9dbe87e

22 files changed

+191
-93
lines changed

packages/integrations/src/captureconsole.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { captureException, captureMessage, convertIntegrationFnToClass, getClient, withScope } from '@sentry/core';
1+
import {
2+
captureException,
3+
captureMessage,
4+
convertIntegrationFnToClass,
5+
defineIntegration,
6+
getClient,
7+
withScope,
8+
} from '@sentry/core';
29
import type { CaptureContext, Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
310
import {
411
CONSOLE_LEVELS,
@@ -15,7 +22,7 @@ interface CaptureConsoleOptions {
1522

1623
const INTEGRATION_NAME = 'CaptureConsole';
1724

18-
const captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {
25+
const _captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {
1926
const levels = options.levels || CONSOLE_LEVELS;
2027

2128
return {
@@ -38,7 +45,12 @@ const captureConsoleIntegration = ((options: CaptureConsoleOptions = {}) => {
3845
};
3946
}) satisfies IntegrationFn;
4047

41-
/** Send Console API calls as Sentry Events */
48+
export const captureConsoleIntegration = defineIntegration(_captureConsoleIntegration);
49+
50+
/**
51+
* Send Console API calls as Sentry Events.
52+
* @deprecated Use `captureConsoleIntegration()` instead.
53+
*/
4254
// eslint-disable-next-line deprecation/deprecation
4355
export const CaptureConsole = convertIntegrationFnToClass(
4456
INTEGRATION_NAME,

packages/integrations/src/contextlines.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
33
import { GLOBAL_OBJ, addContextToFrame, stripUrlQueryAndFragment } from '@sentry/utils';
44

@@ -18,7 +18,7 @@ interface ContextLinesOptions {
1818
frameContextLines?: number;
1919
}
2020

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

2424
return {
@@ -31,6 +31,8 @@ const contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
3131
};
3232
}) satisfies IntegrationFn;
3333

34+
export const contextLinesIntegration = defineIntegration(_contextLinesIntegration);
35+
3436
/**
3537
* Collects source context lines around the lines of stackframes pointing to JS embedded in
3638
* the current page's HTML.
@@ -41,6 +43,8 @@ const contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
4143
*
4244
* Use this integration if you have inline JS code in HTML pages that can't be accessed
4345
* by our backend (e.g. due to a login-protected page).
46+
*
47+
* @deprecated Use `contextLinesIntegration()` instead.
4448
*/
4549
// eslint-disable-next-line deprecation/deprecation
4650
export const ContextLines = convertIntegrationFnToClass(INTEGRATION_NAME, contextLinesIntegration) as IntegrationClass<

packages/integrations/src/debug.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33
import { consoleSandbox } from '@sentry/utils';
44

@@ -11,7 +11,7 @@ interface DebugOptions {
1111
debugger?: boolean;
1212
}
1313

14-
const debugIntegration = ((options: DebugOptions = {}) => {
14+
const _debugIntegration = ((options: DebugOptions = {}) => {
1515
const _options = {
1616
debugger: false,
1717
stringify: false,
@@ -53,9 +53,13 @@ const debugIntegration = ((options: DebugOptions = {}) => {
5353
};
5454
}) satisfies IntegrationFn;
5555

56+
export const debugIntegration = defineIntegration(_debugIntegration);
57+
5658
/**
5759
* Integration to debug sent Sentry events.
58-
* This integration should not be used in production
60+
* This integration should not be used in production.
61+
*
62+
* @deprecated Use `debugIntegration()` instead.
5963
*/
6064
// eslint-disable-next-line deprecation/deprecation
6165
export const Debug = convertIntegrationFnToClass(INTEGRATION_NAME, debugIntegration) as IntegrationClass<

packages/integrations/src/dedupe.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Exception, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44

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

77
const INTEGRATION_NAME = 'Dedupe';
88

9-
const dedupeIntegration = (() => {
9+
const _dedupeIntegration = (() => {
1010
let previousEvent: Event | undefined;
1111

1212
return {
@@ -33,7 +33,12 @@ const dedupeIntegration = (() => {
3333
};
3434
}) satisfies IntegrationFn;
3535

36-
/** Deduplication filter */
36+
export const dedupeIntegration = defineIntegration(_dedupeIntegration);
37+
38+
/**
39+
* Deduplication filter.
40+
* @deprecated Use `dedupeIntegration()` instead.
41+
*/
3742
// eslint-disable-next-line deprecation/deprecation
3843
export const Dedupe = convertIntegrationFnToClass(INTEGRATION_NAME, dedupeIntegration) as IntegrationClass<
3944
Integration & { processEvent: (event: Event) => Event }

packages/integrations/src/extraerrordata.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type {
33
Contexts,
44
Event,
@@ -28,7 +28,7 @@ interface ExtraErrorDataOptions {
2828
captureErrorCause: boolean;
2929
}
3030

31-
const extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {}) => {
31+
const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {}) => {
3232
const depth = options.depth || 3;
3333

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

47-
/** Extract additional data for from original exceptions. */
47+
export const extraErrorDataIntegration = defineIntegration(_extraErrorDataIntegration);
48+
49+
/**
50+
* Extract additional data for from original exceptions.
51+
* @deprecated Use `extraErrorDataIntegration()` instead.
52+
*/
4853
// eslint-disable-next-line deprecation/deprecation
4954
export const ExtraErrorData = convertIntegrationFnToClass(
5055
INTEGRATION_NAME,

packages/integrations/src/httpclient.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { captureEvent, convertIntegrationFnToClass, getClient, isSentryRequestUrl } from '@sentry/core';
1+
import {
2+
captureEvent,
3+
convertIntegrationFnToClass,
4+
defineIntegration,
5+
getClient,
6+
isSentryRequestUrl,
7+
} from '@sentry/core';
28
import type {
39
Client,
410
Event as SentryEvent,
@@ -45,7 +51,7 @@ interface HttpClientOptions {
4551
failedRequestTargets: HttpRequestTarget[];
4652
}
4753

48-
const httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
54+
const _httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
4955
const _options: HttpClientOptions = {
5056
failedRequestStatusCodes: [[500, 599]],
5157
failedRequestTargets: [/.*/],
@@ -63,7 +69,12 @@ const httpClientIntegration = ((options: Partial<HttpClientOptions> = {}) => {
6369
};
6470
}) satisfies IntegrationFn;
6571

66-
/** HTTPClient integration creates events for failed client side HTTP requests. */
72+
export const httpClientIntegration = defineIntegration(_httpClientIntegration);
73+
74+
/**
75+
* Create events for failed client side HTTP requests.
76+
* @deprecated Use `httpClientIntegration()` instead.
77+
*/
6778
// eslint-disable-next-line deprecation/deprecation
6879
export const HttpClient = convertIntegrationFnToClass(INTEGRATION_NAME, httpClientIntegration) as IntegrationClass<
6980
Integration & { setup: (client: Client) => void }

packages/integrations/src/index.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
export { CaptureConsole } from './captureconsole';
2-
export { Debug } from './debug';
3-
export { Dedupe } from './dedupe';
4-
export { ExtraErrorData } from './extraerrordata';
5-
// eslint-disable-next-line deprecation/deprecation
1+
/* eslint-disable deprecation/deprecation */
2+
export { CaptureConsole, captureConsoleIntegration } from './captureconsole';
3+
export { Debug, debugIntegration } from './debug';
4+
export { Dedupe, dedupeIntegration } from './dedupe';
5+
export { ExtraErrorData, extraErrorDataIntegration } from './extraerrordata';
66
export { Offline } from './offline';
7-
export { ReportingObserver } from './reportingobserver';
8-
export { RewriteFrames } from './rewriteframes';
9-
export { SessionTiming } from './sessiontiming';
10-
// eslint-disable-next-line deprecation/deprecation
7+
export { ReportingObserver, reportingObserverIntegration } from './reportingobserver';
8+
export { RewriteFrames, rewriteFramesIntegration } from './rewriteframes';
9+
export { SessionTiming, sessionTimingIntegration } from './sessiontiming';
1110
export { Transaction } from './transaction';
12-
export { HttpClient } from './httpclient';
13-
export { ContextLines } from './contextlines';
11+
export { HttpClient, httpClientIntegration } from './httpclient';
12+
export { ContextLines, contextLinesIntegration } from './contextlines';

packages/integrations/src/reportingobserver.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureMessage, convertIntegrationFnToClass, getClient, withScope } from '@sentry/core';
1+
import { captureMessage, convertIntegrationFnToClass, defineIntegration, getClient, withScope } from '@sentry/core';
22
import type { Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33
import { GLOBAL_OBJ, supportsReportingObserver } from '@sentry/utils';
44

@@ -48,7 +48,7 @@ interface ReportingObserverOptions {
4848

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

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

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

118-
/** Reporting API integration - https://w3c.github.io/reporting/ */
118+
export const reportingObserverIntegration = defineIntegration(_reportingObserverIntegration);
119+
120+
/**
121+
* Reporting API integration - https://w3c.github.io/reporting/
122+
* @deprecated Use `reportingObserverIntegration()` instead.
123+
*/
119124
// eslint-disable-next-line deprecation/deprecation
120125
export const ReportingObserver = convertIntegrationFnToClass(
121126
INTEGRATION_NAME,

packages/integrations/src/rewriteframes.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame, Stacktrace } from '@sentry/types';
33
import { basename, relative } from '@sentry/utils';
44

@@ -12,7 +12,7 @@ interface RewriteFramesOptions {
1212
iteratee?: StackFrameIteratee;
1313
}
1414

15-
const rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {
15+
const _rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {
1616
const root = options.root;
1717
const prefix = options.prefix || 'app:///';
1818

@@ -85,7 +85,12 @@ const rewriteFramesIntegration = ((options: RewriteFramesOptions = {}) => {
8585
};
8686
}) satisfies IntegrationFn;
8787

88-
/** Rewrite event frames paths */
88+
export const rewriteFramesIntegration = defineIntegration(_rewriteFramesIntegration);
89+
90+
/**
91+
* Rewrite event frames paths.
92+
* @deprecated Use `rewriteFramesIntegration()` instead.
93+
*/
8994
// eslint-disable-next-line deprecation/deprecation
9095
export const RewriteFrames = convertIntegrationFnToClass(
9196
INTEGRATION_NAME,

packages/integrations/src/sessiontiming.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33

44
const INTEGRATION_NAME = 'SessionTiming';
55

6-
const sessionTimingIntegration = (() => {
6+
const _sessionTimingIntegration = (() => {
77
const startTime = Date.now();
88

99
return {
@@ -26,7 +26,12 @@ const sessionTimingIntegration = (() => {
2626
};
2727
}) satisfies IntegrationFn;
2828

29-
/** This function adds duration since Sentry was initialized till the time event was sent */
29+
export const sessionTimingIntegration = defineIntegration(_sessionTimingIntegration);
30+
31+
/**
32+
* This function adds duration since Sentry was initialized till the time event was sent.
33+
* @deprecated Use `sessionTimingIntegration()` instead.
34+
*/
3035
// eslint-disable-next-line deprecation/deprecation
3136
export const SessionTiming = convertIntegrationFnToClass(
3237
INTEGRATION_NAME,

0 commit comments

Comments
 (0)