Skip to content

Commit 0d43883

Browse files
committed
feat(core)!: Remove standalone Client interface
Instead this now is based on the `BaseClient` class.
1 parent 117a3b4 commit 0d43883

34 files changed

+86
-472
lines changed

docs/migration/v8-to-v9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ This led to some duplication, where we had to keep an interface in `@sentry/type
146146
Since v9, the types have been merged into `@sentry/core`, which removed some of this duplication. This means that certain things that used to be a separate interface, will not expect an actual instance of the class/concrete implementation. This should not affect most users, unless you relied on passing things with a similar shape to internal methods. The following types are affected:
147147

148148
- `Scope` now always expects the `Scope` class
149+
- `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`.
149150

150151
# No Version Support Timeline
151152

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 '../baseclient';
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

Lines changed: 22 additions & 8 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,
@@ -63,10 +64,10 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
6364
*
6465
* Call the constructor with the corresponding options
6566
* specific to the client subclass. To access these options later, use
66-
* {@link Client.getOptions}.
67+
* {@link BaseClient.getOptions}.
6768
*
6869
* If a Dsn is specified in the options, it will be parsed and stored. Use
69-
* {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is
70+
* {@link BaseClient.getDsn} to retrieve the Dsn at any moment. In case the Dsn is
7071
* invalid, the constructor will throw a {@link SentryException}. Note that
7172
* without a valid Dsn, the SDK will not send any events to Sentry.
7273
*
@@ -76,9 +77,9 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
7677
* method and extend the resulting prepared event.
7778
*
7879
* To issue automatically created events (e.g. via instrumentation), use
79-
* {@link Client.captureEvent}. It will prepare the event and pass it through
80+
* {@link BaseClient.captureEvent}. It will prepare the event and pass it through
8081
* the callback lifecycle. To issue auto-breadcrumbs, use
81-
* {@link Client.addBreadcrumb}.
82+
* {@link BaseClient.addBreadcrumb}.
8283
*
8384
* @example
8485
* class NodeClient extends BaseClient<NodeOptions> {
@@ -89,7 +90,7 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
8990
* // ...
9091
* }
9192
*/
92-
export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
93+
export abstract class BaseClient<O extends ClientOptions> {
9394
/** Options passed to the SDK. */
9495
protected readonly _options: O;
9596

@@ -243,6 +244,17 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
243244
updateSession(session, { init: false });
244245
}
245246

247+
/**
248+
* Create a cron monitor check in and send it to Sentry. This method is not available on all clients.
249+
*
250+
* @param checkIn An object that describes a check in.
251+
* @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
252+
* to create a monitor automatically when sending a check in.
253+
* @param scope An optional scope containing event metadata.
254+
* @returns A string representing the id of the check in.
255+
*/
256+
public captureCheckIn?(checkIn: CheckIn, monitorConfig?: MonitorConfig, scope?: Scope): string;
257+
246258
/**
247259
* @inheritDoc
248260
*/
@@ -452,7 +464,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
452464
/** @inheritdoc */
453465
public on(
454466
hook: 'beforeSendFeedback',
455-
callback: (feedback: FeedbackEvent, options?: { includeReplay: boolean }) => void,
467+
callback: (feedback: FeedbackEvent, options?: { includeReplay?: boolean }) => void,
456468
): () => void;
457469

458470
/** @inheritdoc */
@@ -547,7 +559,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
547559
public emit(hook: 'createDsc', dsc: DynamicSamplingContext, rootSpan?: Span): void;
548560

549561
/** @inheritdoc */
550-
public emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay: boolean }): void;
562+
public emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay?: boolean }): void;
551563

552564
/** @inheritdoc */
553565
public emit(
@@ -948,6 +960,8 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
948960
): PromiseLike<Event>;
949961
}
950962

963+
export type Client<O extends ClientOptions = ClientOptions> = BaseClient<O>;
964+
951965
/**
952966
* Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.
953967
*/

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';
2+
import type { Client } from './baseclient';
23
import { getGlobalSingleton, getMainCarrier } from './carrier';
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 './baseclient';
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 './baseclient';
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,3 +1,4 @@
1+
import type { Client } from './baseclient';
12
import { addBreadcrumb } from './breadcrumbs';
23
import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes';
34
import {
@@ -11,7 +12,7 @@ import {
1112
setUser,
1213
startSession,
1314
} from './exports';
14-
import type { Client, EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from './types-hoist';
15+
import type { EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from './types-hoist';
1516

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

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type { CaptureContext, ScopeContext, ScopeData } from './scope';
5252
export { notifyEventProcessors } from './eventProcessors';
5353
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
5454
export { BaseClient } from './baseclient';
55+
export type { Client } from './baseclient';
5556
export { ServerRuntimeClient } from './server-runtime-client';
5657
export { initAndBind, setCurrentClient } from './sdk';
5758
export { createTransport } from './transports/base';

packages/core/src/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { Client } from './baseclient';
12
import { getClient } from './currentScopes';
2-
import type { Client, Event, EventHint, Integration, IntegrationFn, Options } from './types-hoist';
3-
43
import { DEBUG_BUILD } from './debug-build';
4+
import type { Event, EventHint, Integration, IntegrationFn, Options } from './types-hoist';
55
import { logger } from './utils-hoist/logger';
66

77
export const installedIntegrations: string[] = [];

packages/core/src/integrations/functiontostring.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { Client } from '../baseclient';
12
import { getClient } from '../currentScopes';
23
import { defineIntegration } from '../integration';
3-
import type { Client, IntegrationFn, WrappedFunction } from '../types-hoist';
4+
import type { IntegrationFn, WrappedFunction } from '../types-hoist';
45
import { getOriginalFunction } from '../utils-hoist/object';
56

67
let originalFunctionToString: () => void;

packages/core/src/scope.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable max-lines */
2+
import type { Client } from './baseclient';
3+
import { updateSession } from './session';
24
import type {
35
Attachment,
46
Breadcrumb,
5-
Client,
67
Context,
78
Contexts,
89
Event,
@@ -17,8 +18,6 @@ import type {
1718
Span,
1819
User,
1920
} from './types-hoist';
20-
21-
import { updateSession } from './session';
2221
import { isPlainObject } from './utils-hoist/is';
2322
import { logger } from './utils-hoist/logger';
2423
import { uuid4 } from './utils-hoist/misc';

packages/core/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { Client } from './baseclient';
12
import { getCurrentScope } from './currentScopes';
2-
import type { Client, ClientOptions } from './types-hoist';
3-
43
import { DEBUG_BUILD } from './debug-build';
4+
import type { ClientOptions } from './types-hoist';
55
import { consoleSandbox, logger } from './utils-hoist/logger';
66

77
/** A class object that can instantiate Client objects. */

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Client, DynamicSamplingContext, Span } from '../types-hoist';
2-
1+
import type { Client } from '../baseclient';
32
import { DEFAULT_ENVIRONMENT } from '../constants';
43
import { getClient } from '../currentScopes';
54
import type { Scope } from '../scope';
65
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
6+
import type { DynamicSamplingContext, Span } from '../types-hoist';
77
import {
88
baggageHeaderToDynamicSamplingContext,
99
dynamicSamplingContextToSentryBaggageHeader,

0 commit comments

Comments
 (0)