Skip to content

Commit b8c83be

Browse files
authored
feat(core)!: Remove standalone Client interface & deprecate BaseClient (#14800)
This PR renames the `BaseClient` class to `Client`, makes the `ClientOptions` optional on `Client`. It keeps a deprecated `BaseClient` alias around, we can remove that in v9 (it does not really hurt to keep it too much, IMHO). Closes #9840
1 parent c347dae commit b8c83be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+122
-498
lines changed

docs/migration/v8-to-v9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ Since v9, the types have been merged into `@sentry/core`, which removed some of
221221
- The `Request` type has been removed. Use `RequestEventData` type instead.
222222
- The `IntegrationClass` type is no longer exported - it was not used anymore. Instead, use `Integration` or `IntegrationFn`.
223223
- The `samplingContext.request` attribute in the `tracesSampler` has been removed. Use `samplingContext.normalizedRequest` instead. Note that the type of `normalizedRequest` differs from `request`.
224+
- `Client` now always expects the `BaseClient` class - there is no more abstract `Client` that can be implemented! Any `Client` class has to extend from `BaseClient`.
224225

225226
# No Version Support Timeline
226227

packages/browser-utils/test/utils/TestClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseClient, createTransport, initAndBind } from '@sentry/core';
1+
import { Client, createTransport, initAndBind } from '@sentry/core';
22
import { resolvedSyncPromise } from '@sentry/core';
33
import type {
44
BrowserClientReplayOptions,
@@ -10,7 +10,7 @@ import type {
1010

1111
export interface TestClientOptions extends ClientOptions, BrowserClientReplayOptions {}
1212

13-
export class TestClient extends BaseClient<TestClientOptions> {
13+
export class TestClient extends Client<TestClientOptions> {
1414
public constructor(options: TestClientOptions) {
1515
super(options);
1616
}

packages/browser/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
Scope,
1010
SeverityLevel,
1111
} from '@sentry/core';
12-
import { BaseClient, applySdkMetadata, getSDKSource } from '@sentry/core';
12+
import { Client, applySdkMetadata, getSDKSource } from '@sentry/core';
1313
import { eventFromException, eventFromMessage } from './eventbuilder';
1414
import { WINDOW } from './helpers';
1515
import type { BrowserTransportOptions } from './transports/types';
@@ -58,7 +58,7 @@ export type BrowserClientOptions = ClientOptions<BrowserTransportOptions> &
5858
* @see BrowserOptions for documentation on configuration options.
5959
* @see SentryClient for usage documentation.
6060
*/
61-
export class BrowserClient extends BaseClient<BrowserClientOptions> {
61+
export class BrowserClient extends Client<BrowserClientOptions> {
6262
/**
6363
* Creates a new Browser SDK instance.
6464
*

packages/core/src/asyncContext/stackStrategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { Client } from '../client';
12
import { getDefaultCurrentScope, getDefaultIsolationScope } from '../defaultScopes';
23
import { Scope } from '../scope';
3-
import type { Client } from '../types-hoist';
44
import { isThenable } from '../utils-hoist/is';
55
import { getMainCarrier, getSentryCarrier } from './../carrier';
66
import type { AsyncContextStrategy } from './types';

packages/core/src/baseclient.ts renamed to packages/core/src/client.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type {
33
Breadcrumb,
44
BreadcrumbHint,
5-
Client,
5+
CheckIn,
66
ClientOptions,
77
DataCategory,
88
DsnComponents,
@@ -15,6 +15,7 @@ import type {
1515
EventProcessor,
1616
FeedbackEvent,
1717
Integration,
18+
MonitorConfig,
1819
Outcome,
1920
ParameterizedString,
2021
SdkMetadata,
@@ -71,7 +72,7 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
7172
* without a valid Dsn, the SDK will not send any events to Sentry.
7273
*
7374
* Before sending an event, it is passed through
74-
* {@link BaseClient._prepareEvent} to add SDK information and scope data
75+
* {@link Client._prepareEvent} to add SDK information and scope data
7576
* (breadcrumbs and context). To add more custom information, override this
7677
* method and extend the resulting prepared event.
7778
*
@@ -81,15 +82,15 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
8182
* {@link Client.addBreadcrumb}.
8283
*
8384
* @example
84-
* class NodeClient extends BaseClient<NodeOptions> {
85+
* class NodeClient extends Client<NodeOptions> {
8586
* public constructor(options: NodeOptions) {
8687
* super(options);
8788
* }
8889
*
8990
* // ...
9091
* }
9192
*/
92-
export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
93+
export abstract class Client<O extends ClientOptions = ClientOptions> {
9394
/** Options passed to the SDK. */
9495
protected readonly _options: O;
9596

@@ -234,6 +235,17 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
234235
updateSession(session, { init: false });
235236
}
236237

238+
/**
239+
* Create a cron monitor check in and send it to Sentry. This method is not available on all clients.
240+
*
241+
* @param checkIn An object that describes a check in.
242+
* @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
243+
* to create a monitor automatically when sending a check in.
244+
* @param scope An optional scope containing event metadata.
245+
* @returns A string representing the id of the check in.
246+
*/
247+
public captureCheckIn?(checkIn: CheckIn, monitorConfig?: MonitorConfig, scope?: Scope): string;
248+
237249
/**
238250
* @inheritDoc
239251
*/
@@ -443,7 +455,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
443455
/** @inheritdoc */
444456
public on(
445457
hook: 'beforeSendFeedback',
446-
callback: (feedback: FeedbackEvent, options?: { includeReplay: boolean }) => void,
458+
callback: (feedback: FeedbackEvent, options?: { includeReplay?: boolean }) => void,
447459
): () => void;
448460

449461
/** @inheritdoc */
@@ -538,7 +550,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
538550
public emit(hook: 'createDsc', dsc: DynamicSamplingContext, rootSpan?: Span): void;
539551

540552
/** @inheritdoc */
541-
public emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay: boolean }): void;
553+
public emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay?: boolean }): void;
542554

543555
/** @inheritdoc */
544556
public emit(
@@ -946,6 +958,16 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
946958
): PromiseLike<Event>;
947959
}
948960

961+
/**
962+
* @deprecated Use `Client` instead. This alias may be removed in a future major version.
963+
*/
964+
export type BaseClient = Client;
965+
966+
/**
967+
* @deprecated Use `Client` instead. This alias may be removed in a future major version.
968+
*/
969+
export const BaseClient = Client;
970+
949971
/**
950972
* Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.
951973
*/

packages/core/src/currentScopes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { getAsyncContextStrategy } from './asyncContext';
22
import { getGlobalSingleton, getMainCarrier } from './carrier';
3+
import type { Client } from './client';
34
import { Scope } from './scope';
4-
import type { Client, TraceContext } from './types-hoist';
5+
import type { TraceContext } from './types-hoist';
56
import { dropUndefinedKeys } from './utils-hoist/object';
67

78
/**

packages/core/src/envelope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { Client } from './client';
12
import { getDynamicSamplingContextFromSpan } from './tracing/dynamicSamplingContext';
23
import type { SentrySpan } from './tracing/sentrySpan';
34
import type {
4-
Client,
55
DsnComponents,
66
DynamicSamplingContext,
77
Event,

packages/core/src/exports.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes';
2+
import { DEBUG_BUILD } from './debug-build';
3+
import type { CaptureContext } from './scope';
4+
import { closeSession, makeSession, updateSession } from './session';
15
import type {
26
CheckIn,
37
Event,
@@ -13,11 +17,6 @@ import type {
1317
SeverityLevel,
1418
User,
1519
} from './types-hoist';
16-
17-
import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes';
18-
import { DEBUG_BUILD } from './debug-build';
19-
import type { CaptureContext } from './scope';
20-
import { closeSession, makeSession, updateSession } from './session';
2120
import { isThenable } from './utils-hoist/is';
2221
import { logger } from './utils-hoist/logger';
2322
import { uuid4 } from './utils-hoist/misc';

packages/core/src/fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { Client } from './client';
12
import type { Scope } from './scope';
23
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';
34
import { SPAN_STATUS_ERROR, setHttpStatus, startInactiveSpan } from './tracing';
45
import { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';
5-
import type { Client, HandlerDataFetch, Span, SpanOrigin } from './types-hoist';
6+
import type { HandlerDataFetch, Span, SpanOrigin } from './types-hoist';
67
import { SENTRY_BAGGAGE_KEY_PREFIX } from './utils-hoist/baggage';
78
import { isInstanceOf } from './utils-hoist/is';
89
import { parseUrl } from './utils-hoist/url';

packages/core/src/getCurrentHubShim.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { addBreadcrumb } from './breadcrumbs';
2+
import type { Client } from './client';
23
import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes';
34
import {
45
captureEvent,
@@ -12,7 +13,7 @@ import {
1213
setUser,
1314
startSession,
1415
} from './exports';
15-
import type { Client, EventHint, Hub, Integration, SeverityLevel } from './types-hoist';
16+
import type { EventHint, Hub, Integration, SeverityLevel } from './types-hoist';
1617

1718
/**
1819
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.

0 commit comments

Comments
 (0)