Skip to content

Commit 95473a9

Browse files
AbhiPrasadcadesalaberry
authored andcommitted
ref(v8): change integration.setupOnce signature (getsentry#11238)
Make `integration.setupOnce` accept no arguments. This will allow us to easily remove `addGlobalEventProcessor` which is deprecated API. This also means we can remove `IntegrationFnResult`, as the type signature of the functional and class based integrations are now the same. Next up - remove `addGlobalEventProcessor`!
1 parent a4b66e1 commit 95473a9

File tree

15 files changed

+53
-141
lines changed

15 files changed

+53
-141
lines changed

packages/core/src/integration.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import type {
2-
Client,
3-
Event,
4-
EventHint,
5-
Integration,
6-
IntegrationClass,
7-
IntegrationFn,
8-
IntegrationFnResult,
9-
Options,
10-
} from '@sentry/types';
1+
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn, Options } from '@sentry/types';
112
import { arrayify, logger } from '@sentry/utils';
123
import { getClient } from './currentScopes';
134

145
import { DEBUG_BUILD } from './debug-build';
15-
import { addGlobalEventProcessor } from './eventProcessors';
16-
import { getCurrentHub } from './hub';
176

187
declare module '@sentry/types' {
198
interface Integration {
@@ -130,8 +119,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
130119

131120
// `setupOnce` is only called the first time
132121
if (installedIntegrations.indexOf(integration.name) === -1 && typeof integration.setupOnce === 'function') {
133-
// eslint-disable-next-line deprecation/deprecation
134-
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
122+
integration.setupOnce();
135123
installedIntegrations.push(integration.name);
136124
}
137125

@@ -203,6 +191,6 @@ export function convertIntegrationFnToClass<Fn extends IntegrationFn>(
203191
* Define an integration function that can be used to create an integration instance.
204192
* Note that this by design hides the implementation details of the integration, as they are considered internal.
205193
*/
206-
export function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => IntegrationFnResult {
194+
export function defineIntegration<Fn extends IntegrationFn>(fn: Fn): (...args: Parameters<Fn>) => Integration {
207195
return fn;
208196
}

packages/core/test/lib/sdk.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, Integration, IntegrationFnResult } from '@sentry/types';
1+
import type { Client, Integration } from '@sentry/types';
22
import { captureCheckIn, getCurrentScope, setCurrentClient } from '../../src';
33

44
import { installedIntegrations } from '../../src/integration';
@@ -43,20 +43,20 @@ describe('SDK', () => {
4343
name: 'integration1',
4444
setupOnce: jest.fn(() => list.push('setupOnce1')),
4545
afterAllSetup: jest.fn(() => list.push('afterAllSetup1')),
46-
} satisfies IntegrationFnResult;
46+
} satisfies Integration;
4747

4848
const integration2 = {
4949
name: 'integration2',
5050
setupOnce: jest.fn(() => list.push('setupOnce2')),
5151
setup: jest.fn(() => list.push('setup2')),
5252
afterAllSetup: jest.fn(() => list.push('afterAllSetup2')),
53-
} satisfies IntegrationFnResult;
53+
} satisfies Integration;
5454

5555
const integration3 = {
5656
name: 'integration3',
5757
setupOnce: jest.fn(() => list.push('setupOnce3')),
5858
setup: jest.fn(() => list.push('setup3')),
59-
} satisfies IntegrationFnResult;
59+
} satisfies Integration;
6060

6161
const integrations: Integration[] = [integration1, integration2, integration3];
6262
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, integrations });

packages/core/test/mocks/integration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Event, EventProcessor, Integration } from '@sentry/types';
1+
import type { Client, Event, EventProcessor, Integration } from '@sentry/types';
22

33
import { getClient, getCurrentScope } from '../../src';
44

@@ -27,8 +27,8 @@ export class AddAttachmentTestIntegration implements Integration {
2727

2828
public name: string = 'AddAttachmentTestIntegration';
2929

30-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
31-
addGlobalEventProcessor((event, hint) => {
30+
public setup(client: Client): void {
31+
client.addEventProcessor((event, hint) => {
3232
hint.attachments = [...(hint.attachments || []), { filename: 'integration.file', data: 'great content!' }];
3333
return event;
3434
});

packages/feedback/src/core/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineIntegration, getClient } from '@sentry/core';
2-
import type { IntegrationFn, IntegrationFnResult } from '@sentry/types';
2+
import type { Integration, IntegrationFn } from '@sentry/types';
33
import { isBrowser, logger } from '@sentry/utils';
44
import {
55
ACTOR_LABEL,
@@ -42,7 +42,7 @@ interface PublicFeedbackIntegration {
4242
closeDialog: () => void;
4343
removeWidget: () => void;
4444
}
45-
export type IFeedbackIntegration = IntegrationFnResult & PublicFeedbackIntegration;
45+
export type IFeedbackIntegration = Integration & PublicFeedbackIntegration;
4646

4747
export const _feedbackIntegration = (({
4848
// FeedbackGeneralConfiguration

packages/feedback/src/modal/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineIntegration } from '@sentry/core';
2-
import type { IntegrationFn, IntegrationFnResult } from '@sentry/types';
2+
import type { Integration, IntegrationFn } from '@sentry/types';
33
import { createDialog } from './createDialog';
44

55
interface PublicFeedbackModalIntegration {
@@ -8,7 +8,7 @@ interface PublicFeedbackModalIntegration {
88

99
const INTEGRATION_NAME = 'FeedbackModal';
1010

11-
export type IFeedbackModalIntegration = IntegrationFnResult & PublicFeedbackModalIntegration;
11+
export type IFeedbackModalIntegration = Integration & PublicFeedbackModalIntegration;
1212

1313
export const _feedbackModalIntegration = (() => {
1414
return {

packages/feedback/src/screenshot/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineIntegration } from '@sentry/core';
2-
import type { IntegrationFn, IntegrationFnResult } from '@sentry/types';
2+
import type { Integration, IntegrationFn } from '@sentry/types';
33
import { createInput } from './createInput';
44

55
interface PublicFeedbackScreenshotIntegration {
@@ -8,7 +8,7 @@ interface PublicFeedbackScreenshotIntegration {
88

99
const INTEGRATION_NAME = 'FeedbackScreenshot';
1010

11-
export type IFeedbackScreenshotIntegration = IntegrationFnResult & PublicFeedbackScreenshotIntegration;
11+
export type IFeedbackScreenshotIntegration = Integration & PublicFeedbackScreenshotIntegration;
1212

1313
export const _feedbackScreenshotIntegration = (() => {
1414
return {

packages/node-experimental/src/integrations/anr/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineIntegration, getCurrentScope } from '@sentry/core';
2-
import type { Contexts, Event, EventHint, IntegrationFn, IntegrationFnResult } from '@sentry/types';
2+
import type { Contexts, Event, EventHint, Integration, IntegrationFn } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44
import * as inspector from 'inspector';
55
import { Worker } from 'worker_threads';
@@ -69,10 +69,10 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
6969
// This allows us to call into all integrations to fetch the full context
7070
setImmediate(() => this.startWorker());
7171
},
72-
} as IntegrationFnResult & AnrInternal;
72+
} as Integration & AnrInternal;
7373
}) satisfies IntegrationFn;
7474

75-
type AnrReturn = (options?: Partial<AnrIntegrationOptions>) => IntegrationFnResult & AnrInternal;
75+
type AnrReturn = (options?: Partial<AnrIntegrationOptions>) => Integration & AnrInternal;
7676

7777
export const anrIntegration = defineIntegration(_anrIntegration) as AnrReturn;
7878

packages/node/src/integrations/http.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable max-lines */
22
import type * as http from 'http';
33
import type * as https from 'https';
4-
import type { Hub } from '@sentry/core';
54
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startInactiveSpan } from '@sentry/core';
65
import { defineIntegration, getIsolationScope, hasTracingEnabled } from '@sentry/core';
76
import {
@@ -18,10 +17,8 @@ import {
1817
} from '@sentry/core';
1918
import type {
2019
ClientOptions,
21-
EventProcessor,
2220
Integration,
2321
IntegrationFn,
24-
IntegrationFnResult,
2522
SanitizedRequestData,
2623
TracePropagationTargets,
2724
} from '@sentry/types';
@@ -124,9 +121,8 @@ const _httpIntegration = ((options: HttpIntegrationOptions = {}) => {
124121
shouldCreateSpanForRequest,
125122
}),
126123
};
127-
128124
// eslint-disable-next-line deprecation/deprecation
129-
return new Http(convertedOptions) as unknown as IntegrationFnResult;
125+
return new Http(convertedOptions) as unknown as Integration;
130126
}) satisfies IntegrationFn;
131127

132128
/**
@@ -169,12 +165,9 @@ export class Http implements Integration {
169165
/**
170166
* @inheritDoc
171167
*/
172-
public setupOnce(
173-
_addGlobalEventProcessor: (callback: EventProcessor) => void,
174-
setupOnceGetCurrentHub: () => Hub,
175-
): void {
168+
public setupOnce(): void {
176169
// eslint-disable-next-line deprecation/deprecation
177-
const clientOptions = setupOnceGetCurrentHub().getClient<NodeClient>()?.getOptions();
170+
const clientOptions = getCurrentHub().getClient<NodeClient>()?.getOptions();
178171

179172
// If `tracing` is not explicitly set, we default this based on whether or not tracing is enabled.
180173
// But for compatibility, we only do that if `enableIfHasTracingEnabled` is set.

packages/node/src/integrations/undici/index.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import {
1313
setHttpStatus,
1414
spanToTraceHeader,
1515
} from '@sentry/core';
16-
import type {
17-
EventProcessor,
18-
Integration,
19-
IntegrationFn,
20-
IntegrationFnResult,
21-
Span,
22-
SpanAttributes,
23-
} from '@sentry/types';
16+
import type { Integration, IntegrationFn, Span, SpanAttributes } from '@sentry/types';
2417
import {
2518
LRUMap,
2619
dynamicSamplingContextToSentryBaggageHeader,
@@ -82,7 +75,7 @@ export interface UndiciOptions {
8275

8376
const _nativeNodeFetchintegration = ((options?: Partial<UndiciOptions>) => {
8477
// eslint-disable-next-line deprecation/deprecation
85-
return new Undici(options) as unknown as IntegrationFnResult;
78+
return new Undici(options) as unknown as Integration;
8679
}) satisfies IntegrationFn;
8780

8881
export const nativeNodeFetchintegration = defineIntegration(_nativeNodeFetchintegration);
@@ -125,7 +118,7 @@ export class Undici implements Integration {
125118
/**
126119
* @inheritDoc
127120
*/
128-
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void): void {
121+
public setupOnce(): void {
129122
// Requires Node 16+ to use the diagnostics_channel API.
130123
if (NODE_VERSION.major < 16) {
131124
return;

packages/node/test/integrations/contextlines.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs';
2-
import type { Event, IntegrationFnResult, StackFrame } from '@sentry/types';
2+
import type { Event, Integration, StackFrame } from '@sentry/types';
33
import { parseStackFrames } from '@sentry/utils';
44

55
import { contextLinesIntegration } from '../../src';
@@ -9,10 +9,10 @@ import { getError } from '../helper/error';
99

1010
describe('ContextLines', () => {
1111
let readFileSpy: jest.SpyInstance;
12-
let contextLines: IntegrationFnResult;
12+
let contextLines: Integration;
1313

1414
async function addContext(frames: StackFrame[]): Promise<void> {
15-
await (contextLines as IntegrationFnResult & { processEvent: (event: Event) => Promise<Event> }).processEvent({
15+
await (contextLines as Integration & { processEvent: (event: Event) => Promise<Event> }).processEvent({
1616
exception: { values: [{ stacktrace: { frames } }] },
1717
});
1818
}
@@ -101,7 +101,6 @@ describe('ContextLines', () => {
101101
});
102102

103103
test('parseStack with no context', async () => {
104-
// eslint-disable-next-line deprecation/deprecation
105104
contextLines = contextLinesIntegration({ frameContextLines: 0 });
106105

107106
expect.assertions(1);
@@ -114,7 +113,6 @@ describe('ContextLines', () => {
114113

115114
test('does not attempt to readfile multiple times if it fails', async () => {
116115
expect.assertions(1);
117-
// eslint-disable-next-line deprecation/deprecation
118116
contextLines = contextLinesIntegration();
119117

120118
readFileSpy.mockImplementation(() => {

packages/node/test/integrations/http.test.ts

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as http from 'http';
22
import * as https from 'https';
3-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getSpanDescendants, startSpan } from '@sentry/core';
4-
import type { Hub } from '@sentry/core';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getSpanDescendants, makeMain, startSpan } from '@sentry/core';
54
import { getCurrentHub, getIsolationScope, setCurrentClient } from '@sentry/core';
65
import { Transaction } from '@sentry/core';
76
import { getCurrentScope, setUser, spanToJSON, startInactiveSpan } from '@sentry/core';
@@ -346,7 +345,11 @@ describe('tracing', () => {
346345
setCurrentClient(client);
347346
client.init();
348347
// eslint-disable-next-line deprecation/deprecation
349-
return getCurrentHub();
348+
const hub = getCurrentHub();
349+
// eslint-disable-next-line deprecation/deprecation
350+
makeMain(hub);
351+
352+
return hub;
350353
}
351354

352355
function createTransactionAndPutOnScope() {
@@ -365,12 +368,9 @@ describe('tracing', () => {
365368
// eslint-disable-next-line deprecation/deprecation
366369
const httpIntegration = new HttpIntegration({ tracing: true });
367370

368-
const hub = createHub({ shouldCreateSpanForRequest: () => false });
371+
createHub({ shouldCreateSpanForRequest: () => false });
369372

370-
httpIntegration.setupOnce(
371-
() => undefined,
372-
() => hub as Hub,
373-
);
373+
httpIntegration.setupOnce();
374374

375375
const transaction = createTransactionAndPutOnScope();
376376

@@ -412,12 +412,9 @@ describe('tracing', () => {
412412
// eslint-disable-next-line deprecation/deprecation
413413
const httpIntegration = new HttpIntegration({ tracing: true });
414414

415-
const hub = createHub({ tracePropagationTargets });
415+
createHub({ tracePropagationTargets });
416416

417-
httpIntegration.setupOnce(
418-
() => undefined,
419-
() => hub as Hub,
420-
);
417+
httpIntegration.setupOnce();
421418

422419
createTransactionAndPutOnScope();
423420

@@ -445,12 +442,9 @@ describe('tracing', () => {
445442
// eslint-disable-next-line deprecation/deprecation
446443
const httpIntegration = new HttpIntegration({ tracing: true });
447444

448-
const hub = createHub({ tracePropagationTargets });
445+
createHub({ tracePropagationTargets });
449446

450-
httpIntegration.setupOnce(
451-
() => undefined,
452-
() => hub as Hub,
453-
);
447+
httpIntegration.setupOnce();
454448

455449
createTransactionAndPutOnScope();
456450

@@ -474,12 +468,9 @@ describe('tracing', () => {
474468
},
475469
});
476470

477-
const hub = createHub();
471+
createHub();
478472

479-
httpIntegration.setupOnce(
480-
() => undefined,
481-
() => hub as Hub,
482-
);
473+
httpIntegration.setupOnce();
483474

484475
const transaction = createTransactionAndPutOnScope();
485476

@@ -521,12 +512,9 @@ describe('tracing', () => {
521512
// eslint-disable-next-line deprecation/deprecation
522513
const httpIntegration = new HttpIntegration({ tracing: { tracePropagationTargets } });
523514

524-
const hub = createHub();
515+
createHub();
525516

526-
httpIntegration.setupOnce(
527-
() => undefined,
528-
() => hub as Hub,
529-
);
517+
httpIntegration.setupOnce();
530518

531519
createTransactionAndPutOnScope();
532520

@@ -554,12 +542,9 @@ describe('tracing', () => {
554542
// eslint-disable-next-line deprecation/deprecation
555543
const httpIntegration = new HttpIntegration({ tracing: { tracePropagationTargets } });
556544

557-
const hub = createHub();
545+
createHub();
558546

559-
httpIntegration.setupOnce(
560-
() => undefined,
561-
() => hub as Hub,
562-
);
547+
httpIntegration.setupOnce();
563548

564549
createTransactionAndPutOnScope();
565550

packages/tracing-internal/src/node/integrations/express.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Express implements Integration {
121121
/**
122122
* @inheritDoc
123123
*/
124-
public setupOnce(_: unknown): void {
124+
public setupOnce(): void {
125125
if (!this._router) {
126126
DEBUG_BUILD && logger.error('ExpressIntegration is missing an Express instance');
127127
return;

0 commit comments

Comments
 (0)