Skip to content

Commit 281d77c

Browse files
authored
feat(core): Streamline integration function results to be compatible (#10135)
For the v7 cycle, in order to make this easier to handle. in v8, we need to remove the unused `setupOnce()` calls again. It would be nicer if we could do away with this, but it is pretty hard as the options for a client currently are types as `Integration[]`, and we use these both for setting & getting, making it hard to change this without breaking anything. Now, this is much easier (it basically just works), with the small downsides of shipping a few more bytes - but we can simply remove this in v8 then.
1 parent f87e39f commit 281d77c

37 files changed

+103
-27
lines changed

MIGRATION.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ 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+
## Changed integration interface
14+
15+
In v8, integrations passed to a client will have an optional `setupOnce()` hook.
16+
Currently, this hook is always present, but in v8 you will not be able to rely on this always existing anymore -
17+
any integration _may_ have a `setup` and/or a `setupOnce` hook. Additionally, `setupOnce()` will not receive any arguments anymore.
18+
19+
This should not affect most people, but in the case that you are manually calling `integration.setupOnce()` right now,
20+
make sure to guard it's existence properly.
21+
1322
## Deprecate `Hub`
1423

1524
The `Hub` has been a very important part of the Sentry SDK API up until now. Hubs were the SDK's "unit of concurrency"

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ const breadcrumbsIntegration: IntegrationFn = (options: Partial<BreadcrumbsOptio
6868

6969
return {
7070
name: INTEGRATION_NAME,
71+
// TODO v8: Remove this
72+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
7173
setup(client) {
7274
if (_options.console) {
7375
addConsoleInstrumentationHandler(_getConsoleBreadcrumbHandler(client));

packages/browser/src/integrations/dedupe.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const dedupeIntegration: IntegrationFn = () => {
1111

1212
return {
1313
name: INTEGRATION_NAME,
14+
// TODO v8: Remove this
15+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
1416
processEvent(currentEvent) {
1517
// We want to ignore any non-error type events, e.g. transactions or replays
1618
// These should never be deduped, and also not be compared against as _previousEvent.

packages/browser/src/integrations/httpcontext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const INTEGRATION_NAME = 'HttpContext';
88
const httpContextIntegration: IntegrationFn = () => {
99
return {
1010
name: INTEGRATION_NAME,
11+
// TODO v8: Remove this
12+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
1113
preprocessEvent(event) {
1214
// if none of the information we want exists, don't bother
1315
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {

packages/browser/src/integrations/linkederrors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const linkedErrorsIntegration: IntegrationFn = (options: LinkedErrorsOptions = {
1919

2020
return {
2121
name: INTEGRATION_NAME,
22+
// TODO v8: Remove this
23+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
2224
preprocessEvent(event, hint, client) {
2325
const options = client.getOptions();
2426

packages/browser/src/profiling/integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const INTEGRATION_NAME = 'BrowserProfiling';
2121
const browserProfilingIntegration: IntegrationFn = () => {
2222
return {
2323
name: INTEGRATION_NAME,
24+
// TODO v8: Remove this
25+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
2426
setup(client) {
2527
const scope = getCurrentScope();
2628

packages/core/src/integration.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, Event, EventHint, EventProcessor, Hub, Integration, IntegrationFn, Options } from '@sentry/types';
1+
import type { Client, Event, EventHint, Integration, IntegrationFn, Options } from '@sentry/types';
22
import { arrayify, logger } from '@sentry/utils';
33

44
import { DEBUG_BUILD } from './debug-build';
@@ -171,26 +171,16 @@ export function convertIntegrationFnToClass<Fn extends IntegrationFn>(
171171
fn: Fn,
172172
): Integration & {
173173
id: string;
174-
new (...args: Parameters<Fn>): Integration &
175-
ReturnType<Fn> & {
176-
setupOnce: (addGlobalEventProcessor?: (callback: EventProcessor) => void, getCurrentHub?: () => Hub) => void;
177-
};
174+
new (...args: Parameters<Fn>): Integration & ReturnType<Fn>;
178175
} {
179176
return Object.assign(
180177
// eslint-disable-next-line @typescript-eslint/no-explicit-any
181178
function ConvertedIntegration(...rest: Parameters<Fn>) {
182-
return {
183-
// eslint-disable-next-line @typescript-eslint/no-empty-function
184-
setupOnce: () => {},
185-
...fn(...rest),
186-
};
179+
return fn(...rest);
187180
},
188181
{ id: name },
189182
) as unknown as Integration & {
190183
id: string;
191-
new (...args: Parameters<Fn>): Integration &
192-
ReturnType<Fn> & {
193-
setupOnce: (addGlobalEventProcessor?: (callback: EventProcessor) => void, getCurrentHub?: () => Hub) => void;
194-
};
184+
new (...args: Parameters<Fn>): Integration & ReturnType<Fn>;
195185
};
196186
}

packages/core/src/integrations/inboundfilters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const INTEGRATION_NAME = 'InboundFilters';
3333
const inboundFiltersIntegration: IntegrationFn = (options: Partial<InboundFiltersOptions>) => {
3434
return {
3535
name: INTEGRATION_NAME,
36+
// TODO v8: Remove this
37+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
3638
processEvent(event, _hint, client) {
3739
const clientOptions = client.getOptions();
3840
const mergedOptions = _mergeOptions(options, clientOptions);

packages/core/src/integrations/linkederrors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const linkedErrorsIntegration: IntegrationFn = (options: LinkedErrorsOptions = {
1818

1919
return {
2020
name: INTEGRATION_NAME,
21+
// TODO v8: Remove this
22+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
2123
preprocessEvent(event, hint, client) {
2224
const options = client.getOptions();
2325

packages/core/src/integrations/metadata.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const INTEGRATION_NAME = 'ModuleMetadata';
99
const moduleMetadataIntegration: IntegrationFn = () => {
1010
return {
1111
name: INTEGRATION_NAME,
12+
// TODO v8: Remove this
13+
setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
1214
setup(client) {
1315
if (typeof client.on !== 'function') {
1416
return;

0 commit comments

Comments
 (0)