Skip to content

Commit c5dcb5d

Browse files
authored
feat(browser): Export functional integrations & deprecate classes (#10267)
Also deprecate the `Integrations` hash in browser SDKs. I also forgot to add the integrations from `@sentry/integrations` to the migration.md doc, so adding those as well!
1 parent 2c43038 commit c5dcb5d

File tree

20 files changed

+125
-54
lines changed

20 files changed

+125
-54
lines changed

MIGRATION.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,31 @@ integrations from the `Integrations.XXX` hash, is deprecated in favor of using t
3434

3535
The following list shows how integrations should be migrated:
3636

37-
| Old | New | Packages |
38-
| ------------------------ | ------------------------------- | ------------------------------------------------------------------------------------------------------- |
39-
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
40-
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
41-
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
42-
| `new ModuleMetadata()` | `moduleMetadataIntegration()` | `@sentry/core`, `@sentry/browser` |
43-
| `new RequestData()` | `requestDataIntegration()` | `@sentry/core`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
44-
| `new Wasm() ` | `wasmIntegration()` | `@sentry/wasm` |
45-
| `new Replay()` | `replayIntegration()` | `@sentry/browser` |
46-
| `new ReplayCanvas()` | `replayCanvasIntegration()` | `@sentry/browser` |
47-
| `new Feedback()` | `feedbackIntegration()` | `@sentry/browser` |
37+
| Old | New | Packages |
38+
| ------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------- |
39+
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
40+
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
41+
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
42+
| `new ModuleMetadata()` | `moduleMetadataIntegration()` | `@sentry/core`, `@sentry/browser` |
43+
| `new RequestData()` | `requestDataIntegration()` | `@sentry/core`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
44+
| `new Wasm() ` | `wasmIntegration()` | `@sentry/wasm` |
45+
| `new Replay()` | `replayIntegration()` | `@sentry/browser` |
46+
| `new ReplayCanvas()` | `replayCanvasIntegration()` | `@sentry/browser` |
47+
| `new Feedback()` | `feedbackIntegration()` | `@sentry/browser` |
48+
| `new CaptureConsole()` | `captureConsoleIntegration()` | `@sentry/integrations` |
49+
| `new Debug()` | `debugIntegration()` | `@sentry/integrations` |
50+
| `new Dedupe()` | `dedupeIntegration()` | `@sentry/browser`, `@sentry/integrations`, `@sentry/deno` |
51+
| `new ExtraErrorData()` | `extraErrorDataIntegration()` | `@sentry/integrations` |
52+
| `new ReportingObserver()` | `reportingObserverIntegration()` | `@sentry/integrations` |
53+
| `new RewriteFrames()` | `rewriteFramesIntegration()` | `@sentry/integrations` |
54+
| `new SessionTiming()` | `sessionTimingIntegration()` | `@sentry/integrations` |
55+
| `new HttpClient()` | `httpClientIntegration()` | `@sentry/integrations` |
56+
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/browser` |
57+
| `new Breadcrumbs()` | `breadcrumbsIntegration()` | `@sentry/browser`, `@sentry/deno` |
58+
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` |
59+
| `new HttpContext()` | `httpContextIntegration()` | `@sentry/browser` |
60+
| `new TryCatch()` | `browserApiErrorsIntegration()` | `@sentry/browser`, `@sentry/deno` |
61+
| `new VueIntegration()` | `vueIntegration()` | `@sentry/vue` |
4862

4963
## Deprecate `hub.bindClient()` and `makeMain()`
5064

packages/astro/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import sentryAstro from './index.server';
1414
export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): void;
1515

1616
// We export a merged Integrations object so that users can (at least typing-wise) use all integrations everywhere.
17+
// eslint-disable-next-line deprecation/deprecation
1718
export declare const Integrations: typeof clientSdk.Integrations & typeof serverSdk.Integrations;
1819

20+
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
21+
1922
export declare const defaultIntegrations: Integration[];
2023
export declare const getDefaultIntegrations: (options: Options) => Integration[];
2124
export declare const defaultStackParser: StackParser;

packages/browser/src/exports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,13 @@ export {
102102
// eslint-disable-next-line deprecation/deprecation
103103
wrap,
104104
} from './sdk';
105+
106+
export { breadcrumbsIntegration } from './integrations/breadcrumbs';
107+
export { dedupeIntegration } from './integrations/dedupe';
108+
export { globalHandlersIntegration } from './integrations/globalhandlers';
109+
export { httpContextIntegration } from './integrations/httpcontext';
110+
export { linkedErrorsIntegration } from './integrations/linkederrors';
111+
export { browserApiErrorsIntegration } from './integrations/trycatch';
112+
113+
// eslint-disable-next-line deprecation/deprecation
105114
export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';

packages/browser/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ if (WINDOW.Sentry && WINDOW.Sentry.Integrations) {
1212
windowIntegrations = WINDOW.Sentry.Integrations;
1313
}
1414

15+
/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
1516
const INTEGRATIONS = {
1617
...windowIntegrations,
1718
// eslint-disable-next-line deprecation/deprecation
1819
...CoreIntegrations,
1920
...BrowserIntegrations,
2021
};
2122

23+
// eslint-disable-next-line deprecation/deprecation
2224
export { INTEGRATIONS as Integrations };
2325

2426
export {

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-lines */
2-
import { addBreadcrumb, convertIntegrationFnToClass, getClient } from '@sentry/core';
2+
import { addBreadcrumb, convertIntegrationFnToClass, defineIntegration, getClient } from '@sentry/core';
33
import type {
44
Client,
55
Event as SentryEvent,
@@ -57,7 +57,7 @@ const MAX_ALLOWED_STRING_LENGTH = 1024;
5757

5858
const INTEGRATION_NAME = 'Breadcrumbs';
5959

60-
const breadcrumbsIntegration = ((options: Partial<BreadcrumbsOptions> = {}) => {
60+
const _breadcrumbsIntegration = ((options: Partial<BreadcrumbsOptions> = {}) => {
6161
const _options = {
6262
console: true,
6363
dom: true,
@@ -95,8 +95,12 @@ const breadcrumbsIntegration = ((options: Partial<BreadcrumbsOptions> = {}) => {
9595
};
9696
}) satisfies IntegrationFn;
9797

98+
export const breadcrumbsIntegration = defineIntegration(_breadcrumbsIntegration);
99+
98100
/**
99101
* Default Breadcrumbs instrumentations
102+
*
103+
* @deprecated Use `breadcrumbsIntegration()` instead.
100104
*/
101105
// eslint-disable-next-line deprecation/deprecation
102106
export const Breadcrumbs = convertIntegrationFnToClass(INTEGRATION_NAME, breadcrumbsIntegration) as IntegrationClass<

packages/browser/src/integrations/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/browser/src/integrations/globalhandlers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2-
import { captureEvent, convertIntegrationFnToClass, getClient } from '@sentry/core';
2+
import { captureEvent, convertIntegrationFnToClass, defineIntegration, getClient } from '@sentry/core';
33
import type {
44
Client,
55
Event,
@@ -30,7 +30,7 @@ type GlobalHandlersIntegrations = Record<GlobalHandlersIntegrationsOptionKeys, b
3030

3131
const INTEGRATION_NAME = 'GlobalHandlers';
3232

33-
const globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations> = {}) => {
33+
const _globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations> = {}) => {
3434
const _options = {
3535
onerror: true,
3636
onunhandledrejection: true,
@@ -55,7 +55,12 @@ const globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations>
5555
};
5656
}) satisfies IntegrationFn;
5757

58-
/** Global handlers */
58+
export const globalHandlersIntegration = defineIntegration(_globalHandlersIntegration);
59+
60+
/**
61+
* Global handlers.
62+
* @deprecated Use `globalHandlersIntegration()` instead.
63+
*/
5964
// eslint-disable-next-line deprecation/deprecation
6065
export const GlobalHandlers = convertIntegrationFnToClass(
6166
INTEGRATION_NAME,

packages/browser/src/integrations/httpcontext.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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
import { WINDOW } from '../helpers';
55

66
const INTEGRATION_NAME = 'HttpContext';
77

8-
const httpContextIntegration = (() => {
8+
const _httpContextIntegration = (() => {
99
return {
1010
name: INTEGRATION_NAME,
1111
// TODO v8: Remove this
@@ -33,7 +33,12 @@ const httpContextIntegration = (() => {
3333
};
3434
}) satisfies IntegrationFn;
3535

36-
/** HttpContext integration collects information about HTTP request headers */
36+
export const httpContextIntegration = defineIntegration(_httpContextIntegration);
37+
38+
/**
39+
* HttpContext integration collects information about HTTP request headers.
40+
* @deprecated Use `httpContextIntegration()` instead.
41+
*/
3742
// eslint-disable-next-line deprecation/deprecation
3843
export const HttpContext = convertIntegrationFnToClass(INTEGRATION_NAME, httpContextIntegration) as IntegrationClass<
3944
Integration & { preprocessEvent: (event: Event) => void }

packages/browser/src/integrations/index.ts

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 { GlobalHandlers } from './globalhandlers';
23
export { TryCatch } from './trycatch';
34
export { Breadcrumbs } from './breadcrumbs';

packages/browser/src/integrations/linkederrors.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 { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33
import { applyAggregateErrorsToEvent } from '@sentry/utils';
44
import { exceptionFromError } from '../eventbuilder';
@@ -13,7 +13,7 @@ const DEFAULT_LIMIT = 5;
1313

1414
const INTEGRATION_NAME = 'LinkedErrors';
1515

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

@@ -38,7 +38,12 @@ const linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
3838
};
3939
}) satisfies IntegrationFn;
4040

41-
/** Aggregrate linked errors in an event. */
41+
export const linkedErrorsIntegration = defineIntegration(_linkedErrorsIntegration);
42+
43+
/**
44+
* Aggregrate linked errors in an event.
45+
* @deprecated Use `linkedErrorsIntegration()` instead.
46+
*/
4247
// eslint-disable-next-line deprecation/deprecation
4348
export const LinkedErrors = convertIntegrationFnToClass(INTEGRATION_NAME, linkedErrorsIntegration) as IntegrationClass<
4449
Integration & { preprocessEvent: (event: Event, hint: EventHint, client: Client) => void }

packages/browser/src/integrations/trycatch.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 { Integration, IntegrationClass, IntegrationFn, WrappedFunction } from '@sentry/types';
33
import { fill, getFunctionName, getOriginalFunction } from '@sentry/utils';
44

@@ -50,7 +50,7 @@ interface TryCatchOptions {
5050
eventTarget: boolean | string[];
5151
}
5252

53-
const browserApiErrorsIntegration = ((options: Partial<TryCatchOptions> = {}) => {
53+
const _browserApiErrorsIntegration = ((options: Partial<TryCatchOptions> = {}) => {
5454
const _options = {
5555
XMLHttpRequest: true,
5656
eventTarget: true,
@@ -90,7 +90,12 @@ const browserApiErrorsIntegration = ((options: Partial<TryCatchOptions> = {}) =>
9090
};
9191
}) satisfies IntegrationFn;
9292

93-
/** Wrap timer functions and event targets to catch errors and provide better meta data */
93+
export const browserApiErrorsIntegration = defineIntegration(_browserApiErrorsIntegration);
94+
95+
/**
96+
* Wrap timer functions and event targets to catch errors and provide better meta data.
97+
* @deprecated Use `browserApiErrorsIntegration()` instead.
98+
*/
9499
// eslint-disable-next-line deprecation/deprecation
95100
export const TryCatch = convertIntegrationFnToClass(
96101
INTEGRATION_NAME,

packages/browser/src/sdk.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Hub } from '@sentry/core';
2+
import { functionToStringIntegration, inboundFiltersIntegration } from '@sentry/core';
23
import {
3-
FunctionToString,
4-
InboundFilters,
54
captureSession,
65
getClient,
76
getCurrentHub,
@@ -23,22 +22,25 @@ import { BrowserClient } from './client';
2322
import { DEBUG_BUILD } from './debug-build';
2423
import type { ReportDialogOptions } from './helpers';
2524
import { WINDOW, wrap as internalWrap } from './helpers';
26-
import { Breadcrumbs, Dedupe, GlobalHandlers, HttpContext, LinkedErrors, TryCatch } from './integrations';
25+
import { breadcrumbsIntegration } from './integrations/breadcrumbs';
26+
import { dedupeIntegration } from './integrations/dedupe';
27+
import { globalHandlersIntegration } from './integrations/globalhandlers';
28+
import { httpContextIntegration } from './integrations/httpcontext';
29+
import { linkedErrorsIntegration } from './integrations/linkederrors';
30+
import { browserApiErrorsIntegration } from './integrations/trycatch';
2731
import { defaultStackParser } from './stack-parsers';
2832
import { makeFetchTransport, makeXHRTransport } from './transports';
2933

3034
/** @deprecated Use `getDefaultIntegrations(options)` instead. */
3135
export const defaultIntegrations = [
32-
/* eslint-disable deprecation/deprecation */
33-
new InboundFilters(),
34-
new FunctionToString(),
35-
/* eslint-enable deprecation/deprecation */
36-
new TryCatch(),
37-
new Breadcrumbs(),
38-
new GlobalHandlers(),
39-
new LinkedErrors(),
40-
new Dedupe(),
41-
new HttpContext(),
36+
inboundFiltersIntegration(),
37+
functionToStringIntegration(),
38+
browserApiErrorsIntegration(),
39+
breadcrumbsIntegration(),
40+
globalHandlersIntegration(),
41+
linkedErrorsIntegration(),
42+
dedupeIntegration(),
43+
httpContextIntegration(),
4244
];
4345

4446
/** Get the default integrations for the browser SDK. */

packages/browser/test/unit/integrations/breadcrumbs.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('Breadcrumbs', () => {
88
const client = new BrowserClient({
99
...getDefaultBrowserClientOptions(),
1010
dsn: 'https://username@domain/123',
11+
// eslint-disable-next-line deprecation/deprecation
1112
integrations: [new Breadcrumbs()],
1213
});
1314

packages/deno/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export {
9494
init,
9595
} from './sdk';
9696

97+
export { breadcrumbsIntegration, dedupeIntegration } from '@sentry/browser';
9798
import { Integrations as CoreIntegrations } from '@sentry/core';
9899

99100
import * as DenoIntegrations from './integrations';

packages/deno/src/sdk.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Breadcrumbs, Dedupe } from '@sentry/browser';
1+
import { breadcrumbsIntegration, dedupeIntegration } from '@sentry/browser';
22
import type { ServerRuntimeClientOptions } from '@sentry/core';
3-
import { FunctionToString, InboundFilters, LinkedErrors } from '@sentry/core';
3+
import { functionToStringIntegration, inboundFiltersIntegration, linkedErrorsIntegration } from '@sentry/core';
44
import { getIntegrationsToSetup, initAndBind } from '@sentry/core';
55
import type { Integration, Options, StackParser } from '@sentry/types';
66
import { createStackParser, nodeStackLineParser, stackParserFromStackParserOptions } from '@sentry/utils';
@@ -12,15 +12,13 @@ import type { DenoOptions } from './types';
1212

1313
/** @deprecated Use `getDefaultIntegrations(options)` instead. */
1414
export const defaultIntegrations = [
15-
/* eslint-disable deprecation/deprecation */
1615
// Common
17-
new InboundFilters(),
18-
new FunctionToString(),
19-
new LinkedErrors(),
20-
/* eslint-enable deprecation/deprecation */
16+
inboundFiltersIntegration(),
17+
functionToStringIntegration(),
18+
linkedErrorsIntegration(),
2119
// From Browser
22-
new Dedupe(),
23-
new Breadcrumbs({
20+
dedupeIntegration(),
21+
breadcrumbsIntegration({
2422
dom: false,
2523
history: false,
2624
xhr: false,

packages/nextjs/src/client/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export * from '@sentry/react';
1818
export { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation';
1919
export { captureUnderscoreErrorException } from '../common/_error';
2020

21+
/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
2122
export const Integrations = {
23+
// eslint-disable-next-line deprecation/deprecation
2224
...OriginalIntegrations,
2325
BrowserTracing,
2426
};

packages/nextjs/src/index.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export declare function init(
2020
): void;
2121

2222
// We export a merged Integrations object so that users can (at least typing-wise) use all integrations everywhere.
23+
// eslint-disable-next-line deprecation/deprecation
2324
export declare const Integrations: typeof clientSdk.Integrations &
2425
typeof serverSdk.Integrations &
2526
typeof edgeSdk.Integrations;
2627

28+
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
29+
2730
export declare const defaultIntegrations: Integration[];
2831
export declare const getDefaultIntegrations: (options: Options) => Integration[];
2932
export declare const defaultStackParser: StackParser;

0 commit comments

Comments
 (0)