Skip to content

Commit e50cc8a

Browse files
authored
feat(core): Deprecate integration classes & Integrations.X (#10198)
Instead, export the functional components from core, which users should directly use. This also adds a tiny `defineIntegration` utility which takes care of obscuring the actual integration implementation for external use, so this remains private and we can refactor this if we need to.
1 parent 9c6d501 commit e50cc8a

32 files changed

+183
-43
lines changed

MIGRATION.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ be removed.
1818
Instead of `getCurrentHub()`, use the respective replacement API directly - see [Deprecate Hub](#deprecate-hub) for
1919
details.
2020

21+
## Deprecate class-based integrations
22+
23+
In v7, integrations are classes and can be added as e.g. `integrations: [new Sentry.Integrations.ContextLines()]`. In
24+
v8, integrations will not be classes anymore, but instead functions. Both the use as a class, as well as accessing
25+
integrations from the `Integrations.XXX` hash, is deprecated in favor of using the new functional integrations
26+
27+
- for example, `new Integrations.LinkedErrors()` becomes `linkedErrorsIntegration()`.
28+
29+
The following list shows how integrations should be migrated:
30+
31+
| Old | New |
32+
| ------------------------ | ------------------------------- |
33+
| `new InboundFilters()` | `inboundFiltersIntegrations()` |
34+
| `new FunctionToString()` | `functionToStringIntegration()` |
35+
| `new LinkedErrors()` | `linkedErrorsIntegration()` |
36+
| `new ModuleMetadata()` | `moduleMetadataIntegration()` |
37+
| `new RequestData()` | `requestDataIntegration()` |
38+
2139
## Deprecate `hub.bindClient()` and `makeMain()`
2240

2341
Instead, either directly use `initAndBind()`, or the new APIs `setCurrentClient()` and `client.init()`. See

packages/browser/src/exports.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ export {
6565
setUser,
6666
withScope,
6767
withIsolationScope,
68+
// eslint-disable-next-line deprecation/deprecation
6869
FunctionToString,
70+
// eslint-disable-next-line deprecation/deprecation
6971
InboundFilters,
7072
metrics,
73+
functionToStringIntegration,
74+
inboundFiltersIntegration,
7175
} from '@sentry/core';
7276

7377
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,12 +1,11 @@
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 { setCurrentClient } from '../../src';
77
import {
88
BrowserClient,
9-
Integrations,
109
Scope,
1110
WINDOW,
1211
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
const client = new BrowserClient(options);
275277
setCurrentClient(client);

packages/bun/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export {
7979
startSpanManual,
8080
continueTrace,
8181
metrics,
82+
functionToStringIntegration,
83+
inboundFiltersIntegration,
84+
linkedErrorsIntegration,
85+
requestDataIntegration,
8286
} from '@sentry/core';
8387
export type { SpanStatusType } from '@sentry/core';
8488
export { autoDiscoverNodePerformanceMonitoringIntegrations, cron } from '@sentry/node';
@@ -92,6 +96,7 @@ import { Integrations as NodeIntegrations } from '@sentry/node';
9296
import * as BunIntegrations from './integrations';
9397

9498
const INTEGRATIONS = {
99+
// eslint-disable-next-line deprecation/deprecation
95100
...CoreIntegrations,
96101
...NodeIntegrations,
97102
...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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ export { SDK_VERSION } from './version';
6969
export {
7070
getIntegrationsToSetup,
7171
addIntegration,
72+
defineIntegration,
7273
// eslint-disable-next-line deprecation/deprecation
7374
convertIntegrationFnToClass,
7475
} from './integration';
75-
export { FunctionToString, InboundFilters, LinkedErrors } from './integrations';
7676
export { applyScopeDataToEvent, mergeScopeData } from './utils/applyScopeDataToEvent';
7777
export { prepareEvent } from './utils/prepareEvent';
7878
export { createCheckInEnvelope } from './checkin';
@@ -86,9 +86,23 @@ export {
8686
} from './utils/spanUtils';
8787
export { getRootSpan } from './utils/getRootSpan';
8888
export { DEFAULT_ENVIRONMENT } from './constants';
89+
/* eslint-disable deprecation/deprecation */
8990
export { ModuleMetadata } from './integrations/metadata';
9091
export { RequestData } from './integrations/requestdata';
91-
import * as Integrations from './integrations';
92+
export { InboundFilters } from './integrations/inboundfilters';
93+
export { FunctionToString } from './integrations/functiontostring';
94+
export { LinkedErrors } from './integrations/linkederrors';
95+
/* eslint-enable deprecation/deprecation */
96+
import * as INTEGRATIONS from './integrations';
97+
export { functionToStringIntegration } from './integrations/functiontostring';
98+
export { inboundFiltersIntegration } from './integrations/inboundfilters';
99+
export { linkedErrorsIntegration } from './integrations/linkederrors';
100+
export { moduleMetadataIntegration } from './integrations/metadata';
101+
export { requestDataIntegration } from './integrations/requestdata';
92102
export { metrics } from './metrics/exports';
93103

104+
/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
105+
const Integrations = INTEGRATIONS;
106+
107+
// eslint-disable-next-line deprecation/deprecation
94108
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+
}

0 commit comments

Comments
 (0)