Skip to content

Commit f0cd873

Browse files
committed
feat(v8): Remove deprecated integration methods on client
1 parent d26b25d commit f0cd873

File tree

6 files changed

+108
-35
lines changed

6 files changed

+108
-35
lines changed

dev-packages/browser-integration-tests/suites/replay/canvas/manualSnapshot/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentryTest('can manually snapshot canvas', async ({ getLocalTestUrl, page, brows
3131
expect(incrementalSnapshots).toEqual([]);
3232

3333
await page.evaluate(() => {
34-
(window as any).Sentry.getClient().getIntegrationById('ReplayCanvas').snapshot();
34+
(window as any).Sentry.getClient().getIntegrationByName('ReplayCanvas').snapshot();
3535
});
3636

3737
const { incrementalSnapshots: incrementalSnapshotsManual } = getReplayRecordingContent(await reqPromise3);

packages/core/src/baseclient.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
EventProcessor,
1616
FeedbackEvent,
1717
Integration,
18-
IntegrationClass,
1918
Outcome,
2019
ParameterizedString,
2120
SdkMetadata,
@@ -317,16 +316,6 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
317316
}
318317
}
319318

320-
/**
321-
* Gets an installed integration by its `id`.
322-
*
323-
* @returns The installed integration or `undefined` if no integration with that `id` was installed.
324-
* @deprecated Use `getIntegrationByName()` instead.
325-
*/
326-
public getIntegrationById(integrationId: string): Integration | undefined {
327-
return this.getIntegrationByName(integrationId);
328-
}
329-
330319
/**
331320
* Gets an installed integration by its name.
332321
*
@@ -336,19 +325,6 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
336325
return this._integrations[integrationName] as T | undefined;
337326
}
338327

339-
/**
340-
* Returns the client's instance of the given integration class, it any.
341-
* @deprecated Use `getIntegrationByName()` instead.
342-
*/
343-
public getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
344-
try {
345-
return (this._integrations[integration.id] as T) || null;
346-
} catch (_oO) {
347-
DEBUG_BUILD && logger.warn(`Cannot retrieve integration ${integration.id} from the current Client`);
348-
return null;
349-
}
350-
}
351-
352328
/**
353329
* @inheritDoc
354330
*/

packages/core/src/hub.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ export class Hub implements HubInterface {
428428
const client = this.getClient();
429429
if (!client) return null;
430430
try {
431-
// eslint-disable-next-line deprecation/deprecation
432-
return client.getIntegration(integration);
431+
return client.getIntegrationByName<T>(integration.id) || null;
433432
} catch (_oO) {
434433
DEBUG_BUILD && logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
435434
return null;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import type { Client, EventHint, Hub, Integration, IntegrationClass, Scope, SeverityLevel } from '@sentry/types';
2+
3+
import {
4+
addBreadcrumb,
5+
captureEvent,
6+
endSession,
7+
getCurrentScope,
8+
getIsolationScope,
9+
setContext,
10+
setExtra,
11+
setExtras,
12+
setTag,
13+
setTags,
14+
setUser,
15+
startSession,
16+
withScope,
17+
} from '@sentry/core';
18+
import { getClient } from './api';
19+
20+
/**
21+
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
22+
* @deprecated Use the methods directly.
23+
*/
24+
export function getCurrentHub(): Hub {
25+
return {
26+
isOlderThan(_version: number): boolean {
27+
return false;
28+
},
29+
30+
bindClient(client: Client): void {
31+
const scope = getCurrentScope();
32+
scope.setClient(client);
33+
},
34+
35+
pushScope(): Scope {
36+
// TODO: This does not work and is actually deprecated
37+
return getCurrentScope();
38+
},
39+
40+
popScope(): boolean {
41+
// TODO: This does not work and is actually deprecated
42+
return false;
43+
},
44+
45+
withScope,
46+
getClient: <C extends Client>() => getClient() as C | undefined,
47+
getScope: getCurrentScope,
48+
getIsolationScope,
49+
captureException: (exception: unknown, hint?: EventHint) => {
50+
return getCurrentScope().captureException(exception, hint);
51+
},
52+
captureMessage: (message: string, level?: SeverityLevel, hint?: EventHint) => {
53+
return getCurrentScope().captureMessage(message, level, hint);
54+
},
55+
captureEvent,
56+
addBreadcrumb,
57+
setUser,
58+
setTags,
59+
setTag,
60+
setExtra,
61+
setExtras,
62+
setContext,
63+
64+
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
65+
return getClient().getIntegrationByName<T>(integration.id) || null;
66+
},
67+
68+
startSession,
69+
70+
endSession,
71+
72+
captureSession(endSession?: boolean): void {
73+
// both send the update and pull the session from the scope
74+
if (endSession) {
75+
// eslint-disable-next-line deprecation/deprecation
76+
return this.endSession();
77+
}
78+
79+
// only send the update
80+
_sendSessionUpdate();
81+
},
82+
83+
shouldSendDefaultPii(): boolean {
84+
const client = getClient();
85+
const options = client.getOptions();
86+
return Boolean(options.sendDefaultPii);
87+
},
88+
};
89+
}
90+
91+
/**
92+
* Sends the current Session on the scope
93+
*/
94+
function _sendSessionUpdate(): void {
95+
const scope = getCurrentScope();
96+
const client = getClient();
97+
98+
const session = scope.getSession();
99+
if (session) {
100+
client.captureSession(session);
101+
}
102+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ export class Undici implements Integration {
170170
}
171171

172172
private _onRequestCreate = (message: unknown): void => {
173-
// eslint-disable-next-line deprecation/deprecation
174-
if (!getClient()?.getIntegration(Undici)) {
173+
if (!getClient()?.getIntegrationByName('Undici')) {
175174
return;
176175
}
177176

@@ -229,8 +228,7 @@ export class Undici implements Integration {
229228
};
230229

231230
private _onRequestEnd = (message: unknown): void => {
232-
// eslint-disable-next-line deprecation/deprecation
233-
if (!getClient()?.getIntegration(Undici)) {
231+
if (!getClient()?.getIntegrationByName('Undici')) {
234232
return;
235233
}
236234

@@ -269,8 +267,7 @@ export class Undici implements Integration {
269267
};
270268

271269
private _onRequestError = (message: unknown): void => {
272-
// eslint-disable-next-line deprecation/deprecation
273-
if (!getClient()?.getIntegration(Undici)) {
270+
if (!getClient()?.getIntegrationByName('Undici')) {
274271
return;
275272
}
276273

packages/opentelemetry/src/custom/getCurrentHub.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export function getCurrentHub(): Hub {
6262
setContext,
6363

6464
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
65-
// eslint-disable-next-line deprecation/deprecation
66-
return getClient()?.getIntegration(integration) || null;
65+
return getClient()?.getIntegrationByName<T>(integration) || null;
6766
},
6867

6968
startSession,

0 commit comments

Comments
 (0)