Skip to content

Commit aefdd77

Browse files
committed
ref(core): make remaining client methods required
This makes the following required: * `captureSession` * `getSdkMetadata` * `addEventProcessor` * `getEventProcessor` * `getIntegrationByName` * `addIntegration` * `init` * `captureAggregratMetrics`
1 parent 6bfe9a5 commit aefdd77

File tree

16 files changed

+37
-67
lines changed

16 files changed

+37
-67
lines changed

packages/core/src/baseclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ function isTransactionEvent(event: Event): event is TransactionEvent {
941941
export function addEventProcessor(callback: EventProcessor): void {
942942
const client = getClient();
943943

944-
if (!client || !client.addEventProcessor) {
944+
if (!client) {
945945
return;
946946
}
947947

packages/core/src/exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ function _sendSessionUpdate(): void {
456456
// TODO (v8): Remove currentScope and only use the isolation scope(?).
457457
// For v7 though, we can't "soft-break" people using getCurrentHub().getScope().setSession()
458458
const session = currentScope.getSession() || isolationScope.getSession();
459-
if (session && client && client.captureSession) {
459+
if (session && client) {
460460
client.captureSession(session);
461461
}
462462
}

packages/core/src/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
145145
client.on('preprocessEvent', (event, hint) => callback(event, hint, client));
146146
}
147147

148-
if (client.addEventProcessor && typeof integration.processEvent === 'function') {
148+
if (typeof integration.processEvent === 'function') {
149149
const callback = integration.processEvent.bind(integration) as typeof integration.processEvent;
150150

151151
const processor = Object.assign((event: Event, hint: EventHint) => callback(event, hint, client), {
@@ -162,7 +162,7 @@ export function setupIntegration(client: Client, integration: Integration, integ
162162
export function addIntegration(integration: Integration): void {
163163
const client = getClient();
164164

165-
if (!client || !client.addIntegration) {
165+
if (!client) {
166166
DEBUG_BUILD && logger.warn(`Cannot add integration "${integration.name}" because no SDK Client is available.`);
167167
return;
168168
}

packages/core/src/metrics/aggregator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class MetricsAggregator implements MetricsAggregatorBase {
153153
* @param flushedBuckets
154154
*/
155155
private _captureMetrics(flushedBuckets: MetricBucket): void {
156-
if (flushedBuckets.size > 0 && this._client.captureAggregateMetrics) {
156+
if (flushedBuckets.size > 0) {
157157
// TODO(@anonrig): Optimization opportunity.
158158
// This copy operation can be avoided if we store the key in the bucketItem.
159159
const buckets = Array.from(flushedBuckets).map(([, bucketItem]) => bucketItem);

packages/core/src/metrics/browser-aggregator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ export class BrowserMetricsAggregator implements MetricsAggregator {
7474
if (this._buckets.size === 0) {
7575
return;
7676
}
77-
if (this._client.captureAggregateMetrics) {
78-
// TODO(@anonrig): Use Object.values() when we support ES6+
79-
const metricBuckets = Array.from(this._buckets).map(([, bucketItem]) => bucketItem);
80-
this._client.captureAggregateMetrics(metricBuckets);
81-
}
77+
78+
// TODO(@anonrig): Use Object.values() when we support ES6+
79+
const metricBuckets = Array.from(this._buckets).map(([, bucketItem]) => bucketItem);
80+
this._client.captureAggregateMetrics(metricBuckets);
81+
8282
this._buckets.clear();
8383
}
8484

packages/core/src/sdk.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function initAndBind<F extends Client, O extends ClientOptions>(
3535

3636
const client = new clientClass(options);
3737
setCurrentClient(client);
38-
initializeClient(client);
38+
client.init();
3939
}
4040

4141
/**
@@ -49,18 +49,3 @@ export function setCurrentClient(client: Client): void {
4949
top.client = client;
5050
top.scope.setClient(client);
5151
}
52-
53-
/**
54-
* Initialize the client for the current scope.
55-
* Make sure to call this after `setCurrentClient()`.
56-
*/
57-
function initializeClient(client: Client): void {
58-
if (client.init) {
59-
client.init();
60-
// TODO v8: Remove this fallback
61-
// eslint-disable-next-line deprecation/deprecation
62-
} else if (client.setupIntegrations) {
63-
// eslint-disable-next-line deprecation/deprecation
64-
client.setupIntegrations();
65-
}
66-
}

packages/core/src/utils/prepareEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function prepareEvent(
7575
addExceptionMechanism(prepared, hint.mechanism);
7676
}
7777

78-
const clientEventProcessors = client && client.getEventProcessors ? client.getEventProcessors() : [];
78+
const clientEventProcessors = client ? client.getEventProcessors() : [];
7979

8080
// This should be the last thing called, since we want that
8181
// {@link Hub.addEventProcessor} gets the finished prepared event.

packages/node-experimental/src/sdk/hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function _sendSessionUpdate(): void {
145145
const client = getClient();
146146

147147
const session = scope.getSession();
148-
if (session && client.captureSession) {
148+
if (session) {
149149
client.captureSession(session);
150150
}
151151
}

packages/node-experimental/src/sdk/init.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,18 @@ export function init(options: NodeExperimentalOptions | undefined = {}): void {
8686

8787
if (options.spotlight) {
8888
const client = getClient();
89-
if (client.addIntegration) {
90-
// force integrations to be setup even if no DSN was set
91-
// If they have already been added before, they will be ignored anyhow
92-
const integrations = client.getOptions().integrations;
93-
for (const integration of integrations) {
94-
client.addIntegration(integration);
95-
}
96-
client.addIntegration(
97-
spotlightIntegration({
98-
sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,
99-
}),
100-
);
89+
90+
// force integrations to be setup even if no DSN was set
91+
// If they have already been added before, they will be ignored anyhow
92+
const integrations = client.getOptions().integrations;
93+
for (const integration of integrations) {
94+
client.addIntegration(integration);
10195
}
96+
client.addIntegration(
97+
spotlightIntegration({
98+
sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,
99+
}),
100+
);
102101
}
103102

104103
// Always init Otel, even if tracing is disabled, because we need it for trace propagation & the HTTP integration

packages/node/src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function init(options: NodeOptions = {}): void {
176176

177177
if (options.spotlight) {
178178
const client = getClient();
179-
if (client && client.addIntegration) {
179+
if (client) {
180180
// force integrations to be setup even if no DSN was set
181181
// If they have already been added before, they will be ignored anyhow
182182
const integrations = client.getOptions().integrations;

packages/opentelemetry/src/setupEventContextTrace.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import { spanHasParentId } from './utils/spanTypes';
55

66
/** Ensure the `trace` context is set on all events. */
77
export function setupEventContextTrace(client: Client): void {
8-
if (!client.addEventProcessor) {
9-
return;
10-
}
11-
128
client.addEventProcessor(event => {
139
const span = getActiveSpan();
1410
if (!span) {

packages/replay/src/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
367367
/* eslint-disable @typescript-eslint/no-non-null-assertion */
368368
try {
369369
const client = getClient()!;
370-
const canvasIntegration = client.getIntegrationByName!('ReplayCanvas') as Integration & {
370+
const canvasIntegration = client.getIntegrationByName('ReplayCanvas') as Integration & {
371371
getOptions(): ReplayCanvasIntegrationOptions;
372372
};
373373
if (!canvasIntegration) {

packages/replay/src/util/addGlobalListeners.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ export function addGlobalListeners(replay: ReplayContainer): void {
2727
// Tag all (non replay) events that get sent to Sentry with the current
2828
// replay ID so that we can reference them later in the UI
2929
const eventProcessor = handleGlobalEventListener(replay, !hasHooks(client));
30-
if (client && client.addEventProcessor) {
31-
client.addEventProcessor(eventProcessor);
32-
} else {
33-
addEventProcessor(eventProcessor);
34-
}
30+
addEventProcessor(eventProcessor);
3531

3632
// If a custom client has no hooks yet, we continue to use the "old" implementation
3733
if (hasHooks(client)) {

packages/replay/src/util/getReplay.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ import type { replayIntegration } from '../integration';
77
// eslint-disable-next-line deprecation/deprecation
88
export function getReplay(): ReturnType<typeof replayIntegration> | undefined {
99
const client = getClient();
10-
return (
11-
client && client.getIntegrationByName && client.getIntegrationByName<ReturnType<typeof replayIntegration>>('Replay')
12-
);
10+
return client && client.getIntegrationByName<ReturnType<typeof replayIntegration>>('Replay');
1311
}

packages/replay/src/util/prepareReplayEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function prepareReplayEvent({
4848
preparedEvent.platform = preparedEvent.platform || 'javascript';
4949

5050
// extract the SDK name because `client._prepareEvent` doesn't add it to the event
51-
const metadata = client.getSdkMetadata && client.getSdkMetadata();
51+
const metadata = client.getSdkMetadata();
5252
const { name, version } = (metadata && metadata.sdk) || {};
5353

5454
preparedEvent.sdk = {

packages/types/src/client.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface Client<O extends ClientOptions = ClientOptions> {
6565
*
6666
* @param session Session to be delivered
6767
*/
68-
captureSession?(session: Session): void;
68+
captureSession(session: Session): void;
6969

7070
/**
7171
* Create a cron monitor check in and send it to Sentry. This method is not available on all clients.
@@ -89,7 +89,7 @@ export interface Client<O extends ClientOptions = ClientOptions> {
8989
*
9090
* TODO (v8): Make this a required method.
9191
*/
92-
getSdkMetadata?(): SdkMetadata | undefined;
92+
getSdkMetadata(): SdkMetadata | undefined;
9393

9494
/**
9595
* Returns the transport that is used by the client.
@@ -121,17 +121,13 @@ export interface Client<O extends ClientOptions = ClientOptions> {
121121

122122
/**
123123
* Adds an event processor that applies to any event processed by this client.
124-
*
125-
* TODO (v8): Make this a required method.
126124
*/
127-
addEventProcessor?(eventProcessor: EventProcessor): void;
125+
addEventProcessor(eventProcessor: EventProcessor): void;
128126

129127
/**
130128
* Get all added event processors for this client.
131-
*
132-
* TODO (v8): Make this a required method.
133129
*/
134-
getEventProcessors?(): EventProcessor[];
130+
getEventProcessors(): EventProcessor[];
135131

136132
/**
137133
* Returns the client's instance of the given integration class, it any.
@@ -140,7 +136,7 @@ export interface Client<O extends ClientOptions = ClientOptions> {
140136
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null;
141137

142138
/** Get the instance of the integration with the given name on the client, if it was added. */
143-
getIntegrationByName?<T extends Integration = Integration>(name: string): T | undefined;
139+
getIntegrationByName<T extends Integration = Integration>(name: string): T | undefined;
144140

145141
/**
146142
* Add an integration to the client.
@@ -150,7 +146,7 @@ export interface Client<O extends ClientOptions = ClientOptions> {
150146
*
151147
* TODO (v8): Make this a required method.
152148
* */
153-
addIntegration?(integration: Integration): void;
149+
addIntegration(integration: Integration): void;
154150

155151
/**
156152
* This is an internal function to setup all integrations that should run on the client.
@@ -162,7 +158,7 @@ export interface Client<O extends ClientOptions = ClientOptions> {
162158
* Initialize this client.
163159
* Call this after the client was set on a scope.
164160
*/
165-
init?(): void;
161+
init(): void;
166162

167163
/** Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`. */
168164
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -191,7 +187,7 @@ export interface Client<O extends ClientOptions = ClientOptions> {
191187
*
192188
* @experimental This API is experimental and might experience breaking changes
193189
*/
194-
captureAggregateMetrics?(metricBucketItems: Array<MetricBucketItem>): void;
190+
captureAggregateMetrics(metricBucketItems: Array<MetricBucketItem>): void;
195191

196192
// HOOKS
197193
// TODO(v8): Make the hooks non-optional.

0 commit comments

Comments
 (0)