Skip to content

Commit f4cbdea

Browse files
committed
feat(core): Deprecate integration classes & Integrations.X
Instead, export the functional components from core, which users should directly use.
1 parent b397b39 commit f4cbdea

32 files changed

+184
-43
lines changed

MIGRATION.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ npx @sentry/migr8@latest
1010
This will let you select which updates to run, and automatically update your code. Make sure to still review all code
1111
changes!
1212

13+
## Deprecate class-based integrations
14+
15+
In v7, integrations are classes and can be added as e.g. `integrations: [new Sentry.Integrations.ContextLines()]`. In
16+
v8, integrations will not be classes anymore, but instead functions. Both the use as a class, as well as accessing
17+
integrations from the `Integrations.XXX` hash, is deprecated in favor of using the new functional integrations
18+
19+
- for example, `new Integrations.LinkedErrors()` becomes `linkedErrorsIntegration()`.
20+
21+
The following list shows how integrations should be migrated:
22+
23+
| Old | New |
24+
| ------------------------ | ------------------------------- |
25+
| `new InboundFilters()` | `inboundFiltersIntegrations()` |
26+
| `new FunctionToString()` | `functionToStringIntegration()` |
27+
| `new LinkedErrors()` | `linkedErrorsIntegration()` |
28+
| `new ModuleMetadata()` | `moduleMetadataIntegration()` |
29+
| `new RequestData()` | `requestDataIntegration()` |
30+
1331
## Deprecated `Transaction` integration
1432

1533
This pluggable integration from `@sentry/integrations` will be removed in v8. It was already undocumented and is not

packages/browser/src/exports.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ export {
6161
setUser,
6262
withScope,
6363
withIsolationScope,
64+
// eslint-disable-next-line deprecation/deprecation
6465
FunctionToString,
66+
// eslint-disable-next-line deprecation/deprecation
6567
InboundFilters,
6668
metrics,
69+
functionToStringIntegration,
70+
inboundFiltersIntegration,
6771
} from '@sentry/core';
6872

6973
export { WINDOW } from './helpers';

packages/browser/src/index.bundle.base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (WINDOW.Sentry && WINDOW.Sentry.Integrations) {
1616
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1717
const INTEGRATIONS: Record<string, new (...args: any[]) => Integration> = {
1818
...windowIntegrations,
19+
// eslint-disable-next-line deprecation/deprecation
1920
...CoreIntegrations,
2021
...BrowserIntegrations,
2122
};

packages/browser/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if (WINDOW.Sentry && WINDOW.Sentry.Integrations) {
1414

1515
const INTEGRATIONS = {
1616
...windowIntegrations,
17+
// eslint-disable-next-line deprecation/deprecation
1718
...CoreIntegrations,
1819
...BrowserIntegrations,
1920
};
@@ -52,7 +53,9 @@ export {
5253
// eslint-disable-next-line deprecation/deprecation
5354
trace,
5455
makeMultiplexedTransport,
56+
// eslint-disable-next-line deprecation/deprecation
5557
ModuleMetadata,
58+
moduleMetadataIntegration,
5659
} from '@sentry/core';
5760
export type { SpanStatusType } from '@sentry/core';
5861
export type { Span } from '@sentry/types';

packages/browser/src/sdk.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Hub } from '@sentry/core';
22
import {
3-
Integrations as CoreIntegrations,
3+
FunctionToString,
4+
InboundFilters,
45
captureSession,
56
getClient,
67
getCurrentHub,
@@ -26,16 +27,18 @@ import { Breadcrumbs, Dedupe, GlobalHandlers, HttpContext, LinkedErrors, TryCatc
2627
import { defaultStackParser } from './stack-parsers';
2728
import { makeFetchTransport, makeXHRTransport } from './transports';
2829

30+
/* eslint-disable deprecation/deprecation */
2931
export const defaultIntegrations = [
30-
new CoreIntegrations.InboundFilters(),
31-
new CoreIntegrations.FunctionToString(),
32+
new InboundFilters(),
33+
new FunctionToString(),
3234
new TryCatch(),
3335
new Breadcrumbs(),
3436
new GlobalHandlers(),
3537
new LinkedErrors(),
3638
new Dedupe(),
3739
new HttpContext(),
3840
];
41+
/* eslint-enable deprecation/deprecation */
3942

4043
/**
4144
* A magic string that build tooling can leverage in order to inject a release value into the SDK.

packages/browser/test/unit/index.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { SDK_VERSION, getReportDialogEndpoint } from '@sentry/core';
1+
import { InboundFilters, SDK_VERSION, getReportDialogEndpoint } from '@sentry/core';
22
import type { WrappedFunction } from '@sentry/types';
33
import * as utils from '@sentry/utils';
44

55
import type { Event } from '../../src';
66
import {
77
BrowserClient,
8-
Integrations,
98
Scope,
109
WINDOW,
1110
addBreadcrumb,
@@ -269,7 +268,10 @@ describe('SentryBrowser', () => {
269268
const options = getDefaultBrowserClientOptions({
270269
beforeSend: localBeforeSend,
271270
dsn,
272-
integrations: [new Integrations.InboundFilters({ ignoreErrors: ['capture'] })],
271+
integrations: [
272+
// eslint-disable-next-line deprecation/deprecation
273+
new InboundFilters({ ignoreErrors: ['capture'] }),
274+
],
273275
});
274276
getCurrentHub().bindClient(new BrowserClient(options));
275277

packages/bun/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export {
7676
startSpanManual,
7777
continueTrace,
7878
metrics,
79+
functionToStringIntegration,
80+
inboundFiltersIntegration,
81+
linkedErrorsIntegration,
82+
moduleMetadataIntegration,
83+
requestDataIntegration,
7984
} from '@sentry/core';
8085
export type { SpanStatusType } from '@sentry/core';
8186
export { autoDiscoverNodePerformanceMonitoringIntegrations, cron } from '@sentry/node';
@@ -89,6 +94,7 @@ import { Integrations as NodeIntegrations } from '@sentry/node';
8994
import * as BunIntegrations from './integrations';
9095

9196
const INTEGRATIONS = {
97+
// eslint-disable-next-line deprecation/deprecation
9298
...CoreIntegrations,
9399
...NodeIntegrations,
94100
...BunIntegrations,

packages/bun/src/sdk.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/* eslint-disable max-lines */
2-
import { Integrations as CoreIntegrations } from '@sentry/core';
2+
import { FunctionToString, InboundFilters, LinkedErrors } from '@sentry/core';
33
import { Integrations as NodeIntegrations, init as initNode } from '@sentry/node';
44

55
import { BunClient } from './client';
66
import { BunServer } from './integrations';
77
import { makeFetchTransport } from './transports';
88
import type { BunOptions } from './types';
99

10+
/* eslint-disable deprecation/deprecation */
1011
export const defaultIntegrations = [
1112
// Common
12-
new CoreIntegrations.InboundFilters(),
13-
new CoreIntegrations.FunctionToString(),
14-
new CoreIntegrations.LinkedErrors(),
13+
new InboundFilters(),
14+
new FunctionToString(),
15+
new LinkedErrors(),
1516
// Native Wrappers
1617
new NodeIntegrations.Console(),
1718
new NodeIntegrations.Http(),
@@ -28,6 +29,7 @@ export const defaultIntegrations = [
2829
// Bun Specific
2930
new BunServer(),
3031
];
32+
/* eslint-enable deprecation/deprecation */
3133

3234
/**
3335
* The Sentry Bun SDK Client.

packages/core/src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export { SDK_VERSION } from './version';
6767
export {
6868
getIntegrationsToSetup,
6969
addIntegration,
70+
defineIntegration,
7071
// eslint-disable-next-line deprecation/deprecation
7172
convertIntegrationFnToClass,
7273
} from './integration';
73-
export { FunctionToString, InboundFilters, LinkedErrors } from './integrations';
7474
export { applyScopeDataToEvent, mergeScopeData } from './utils/applyScopeDataToEvent';
7575
export { prepareEvent } from './utils/prepareEvent';
7676
export { createCheckInEnvelope } from './checkin';
@@ -84,9 +84,20 @@ export {
8484
} from './utils/spanUtils';
8585
export { getRootSpan } from './utils/getRootSpan';
8686
export { DEFAULT_ENVIRONMENT } from './constants';
87+
/* eslint-disable deprecation/deprecation */
8788
export { ModuleMetadata } from './integrations/metadata';
8889
export { RequestData } from './integrations/requestdata';
89-
import * as Integrations from './integrations';
90+
/* eslint-enable deprecation/deprecation */
91+
import * as INTEGRATIONS from './integrations';
92+
export { functionToStringIntegration } from './integrations/functiontostring';
93+
export { inboundFiltersIntegration } from './integrations/inboundfilters';
94+
export { linkedErrorsIntegration } from './integrations/linkederrors';
95+
export { moduleMetadataIntegration } from './integrations/metadata';
96+
export { requestDataIntegration } from './integrations/requestdata';
9097
export { metrics } from './metrics/exports';
9198

99+
/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
100+
const Integrations = INTEGRATIONS;
101+
102+
// eslint-disable-next-line deprecation/deprecation
92103
export { Integrations };

packages/core/src/integration.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn, Options } from '@sentry/types';
1+
import type {
2+
Client,
3+
Event,
4+
EventHint,
5+
Integration,
6+
IntegrationClass,
7+
IntegrationFn,
8+
IntegrationFnResult,
9+
Options,
10+
} from '@sentry/types';
211
import { arrayify, logger } from '@sentry/utils';
312

413
import { DEBUG_BUILD } from './debug-build';
@@ -177,3 +186,11 @@ export function convertIntegrationFnToClass<Fn extends IntegrationFn>(
177186
{ id: name },
178187
) as unknown as IntegrationClass<Integration>;
179188
}
189+
190+
/**
191+
* Define an integration function that can be used to create an integration instance.
192+
* Note that this by design hides the implementation details of the integration, as they are considered internal.
193+
*/
194+
export function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => IntegrationFnResult {
195+
return fn;
196+
}

packages/core/src/integrations/functiontostring.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { Integration, IntegrationClass, IntegrationFn, WrappedFunction } from '@sentry/types';
22
import { getOriginalFunction } from '@sentry/utils';
3-
import { convertIntegrationFnToClass } from '../integration';
3+
import { convertIntegrationFnToClass, defineIntegration } from '../integration';
44

55
let originalFunctionToString: () => void;
66

77
const INTEGRATION_NAME = 'FunctionToString';
88

9-
const functionToStringIntegration = (() => {
9+
const _functionToStringIntegration = (() => {
1010
return {
1111
name: INTEGRATION_NAME,
1212
setupOnce() {
@@ -28,7 +28,12 @@ const functionToStringIntegration = (() => {
2828
};
2929
}) satisfies IntegrationFn;
3030

31-
/** Patch toString calls to return proper name for wrapped functions */
31+
export const functionToStringIntegration = defineIntegration(_functionToStringIntegration);
32+
33+
/**
34+
* Patch toString calls to return proper name for wrapped functions.
35+
* @deprecated Use `functionToStringIntegration()` instead.
36+
*/
3237
// eslint-disable-next-line deprecation/deprecation
3338
export const FunctionToString = convertIntegrationFnToClass(
3439
INTEGRATION_NAME,

packages/core/src/integrations/inboundfilters.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Client, Event, EventHint, Integration, IntegrationClass, Integrati
22
import { getEventDescription, logger, stringMatchesSomePattern } from '@sentry/utils';
33

44
import { DEBUG_BUILD } from '../debug-build';
5-
import { convertIntegrationFnToClass } from '../integration';
5+
import { convertIntegrationFnToClass, defineIntegration } from '../integration';
66

77
// "Script error." is hard coded into browsers for errors that it can't read.
88
// this is the result of a script being pulled in from an external domain and CORS.
@@ -30,7 +30,7 @@ export interface InboundFiltersOptions {
3030
}
3131

3232
const INTEGRATION_NAME = 'InboundFilters';
33-
const inboundFiltersIntegration = ((options: Partial<InboundFiltersOptions> = {}) => {
33+
const _inboundFiltersIntegration = ((options: Partial<InboundFiltersOptions> = {}) => {
3434
return {
3535
name: INTEGRATION_NAME,
3636
// TODO v8: Remove this
@@ -43,7 +43,12 @@ const inboundFiltersIntegration = ((options: Partial<InboundFiltersOptions> = {}
4343
};
4444
}) satisfies IntegrationFn;
4545

46-
/** Inbound filters configurable by the user */
46+
export const inboundFiltersIntegration = defineIntegration(_inboundFiltersIntegration);
47+
48+
/**
49+
* Inbound filters configurable by the user.
50+
* @deprecated Use `inboundFiltersIntegration()` instead.
51+
*/
4752
// eslint-disable-next-line deprecation/deprecation
4853
export const InboundFilters = convertIntegrationFnToClass(
4954
INTEGRATION_NAME,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable deprecation/deprecation */
12
export { FunctionToString } from './functiontostring';
23
export { InboundFilters } from './inboundfilters';
34
export { LinkedErrors } from './linkederrors';

packages/core/src/integrations/linkederrors.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
22
import { applyAggregateErrorsToEvent, exceptionFromError } from '@sentry/utils';
3-
import { convertIntegrationFnToClass } from '../integration';
3+
import { convertIntegrationFnToClass, defineIntegration } from '../integration';
44

55
interface LinkedErrorsOptions {
66
key?: string;
@@ -12,7 +12,7 @@ const DEFAULT_LIMIT = 5;
1212

1313
const INTEGRATION_NAME = 'LinkedErrors';
1414

15-
const linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
15+
const _linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
1616
const limit = options.limit || DEFAULT_LIMIT;
1717
const key = options.key || DEFAULT_KEY;
1818

@@ -36,7 +36,12 @@ const linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
3636
};
3737
}) satisfies IntegrationFn;
3838

39-
/** Adds SDK info to an event. */
39+
export const linkedErrorsIntegration = defineIntegration(_linkedErrorsIntegration);
40+
41+
/**
42+
* Adds SDK info to an event.
43+
* @deprecated Use `linkedErrorsIntegration()` instead.
44+
*/
4045
// eslint-disable-next-line deprecation/deprecation
4146
export const LinkedErrors = convertIntegrationFnToClass(INTEGRATION_NAME, linkedErrorsIntegration) as IntegrationClass<
4247
Integration & { preprocessEvent: (event: Event, hint: EventHint, client: Client) => void }

packages/core/src/integrations/metadata.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { Client, Event, EventHint, EventItem, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
22
import { forEachEnvelopeItem } from '@sentry/utils';
3-
import { convertIntegrationFnToClass } from '../integration';
3+
import { convertIntegrationFnToClass, defineIntegration } from '../integration';
44

55
import { addMetadataToStackFrames, stripMetadataFromStackFrames } from '../metadata';
66

77
const INTEGRATION_NAME = 'ModuleMetadata';
88

9-
const moduleMetadataIntegration = (() => {
9+
const _moduleMetadataIntegration = (() => {
1010
return {
1111
name: INTEGRATION_NAME,
1212
// TODO v8: Remove this
@@ -39,6 +39,8 @@ const moduleMetadataIntegration = (() => {
3939
};
4040
}) satisfies IntegrationFn;
4141

42+
export const moduleMetadataIntegration = defineIntegration(_moduleMetadataIntegration);
43+
4244
/**
4345
* Adds module metadata to stack frames.
4446
*
@@ -47,6 +49,8 @@ const moduleMetadataIntegration = (() => {
4749
* When this integration is added, the metadata passed to the bundler plugin is added to the stack frames of all events
4850
* under the `module_metadata` property. This can be used to help in tagging or routing of events from different teams
4951
* our sources
52+
*
53+
* @deprecated Use `moduleMetadataIntegration()` instead.
5054
*/
5155
// eslint-disable-next-line deprecation/deprecation
5256
export const ModuleMetadata = convertIntegrationFnToClass(

packages/core/src/integrations/requestdata.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
} from '@sentry/types';
1010
import type { AddRequestDataToEventOptions, TransactionNamingScheme } from '@sentry/utils';
1111
import { addRequestDataToEvent, extractPathForTransaction } from '@sentry/utils';
12-
import { convertIntegrationFnToClass } from '../integration';
12+
import { convertIntegrationFnToClass, defineIntegration } from '../integration';
1313
import { spanToJSON } from '../utils/spanUtils';
1414

1515
export type RequestDataIntegrationOptions = {
@@ -55,7 +55,7 @@ const DEFAULT_OPTIONS = {
5555

5656
const INTEGRATION_NAME = 'RequestData';
5757

58-
const requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) => {
58+
const _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) => {
5959
const _addRequestData = addRequestDataToEvent;
6060
const _options: Required<RequestDataIntegrationOptions> = {
6161
...DEFAULT_OPTIONS,
@@ -139,8 +139,13 @@ const requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) =>
139139
};
140140
}) satisfies IntegrationFn;
141141

142-
/** Add data about a request to an event. Primarily for use in Node-based SDKs, but included in `@sentry/integrations`
143-
* so it can be used in cross-platform SDKs like `@sentry/nextjs`. */
142+
export const requestDataIntegration = defineIntegration(_requestDataIntegration);
143+
144+
/**
145+
* Add data about a request to an event. Primarily for use in Node-based SDKs, but included in `@sentry/integrations`
146+
* so it can be used in cross-platform SDKs like `@sentry/nextjs`.
147+
* @deprecated Use `requestDataIntegration()` instead.
148+
*/
144149
// eslint-disable-next-line deprecation/deprecation
145150
export const RequestData = convertIntegrationFnToClass(INTEGRATION_NAME, requestDataIntegration) as IntegrationClass<
146151
Integration & { processEvent: (event: Event, hint: EventHint, client: Client) => Event }

0 commit comments

Comments
 (0)