Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core)!: Remove standalone Client interface & deprecate BaseClient #14800

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/migration/v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ This led to some duplication, where we had to keep an interface in `@sentry/type
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:

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

# No Version Support Timeline

Expand Down
4 changes: 2 additions & 2 deletions packages/browser-utils/test/utils/TestClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseClient, createTransport, initAndBind } from '@sentry/core';
import { Client, createTransport, initAndBind } from '@sentry/core';
import { resolvedSyncPromise } from '@sentry/core';
import type {
BrowserClientReplayOptions,
Expand All @@ -10,7 +10,7 @@ import type {

export interface TestClientOptions extends ClientOptions, BrowserClientReplayOptions {}

export class TestClient extends BaseClient<TestClientOptions> {
export class TestClient extends Client<TestClientOptions> {
public constructor(options: TestClientOptions) {
super(options);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
SeverityLevel,
UserFeedback,
} from '@sentry/core';
import { BaseClient, applySdkMetadata, getSDKSource, logger } from '@sentry/core';
import { Client, applySdkMetadata, getSDKSource, logger } from '@sentry/core';
import { DEBUG_BUILD } from './debug-build';
import { eventFromException, eventFromMessage } from './eventbuilder';
import { WINDOW } from './helpers';
Expand Down Expand Up @@ -61,7 +61,7 @@ export type BrowserClientOptions = ClientOptions<BrowserTransportOptions> &
* @see BrowserOptions for documentation on configuration options.
* @see SentryClient for usage documentation.
*/
export class BrowserClient extends BaseClient<BrowserClientOptions> {
export class BrowserClient extends Client<BrowserClientOptions> {
/**
* Creates a new Browser SDK instance.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/asyncContext/stackStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Client } from '../client';
import { getDefaultCurrentScope, getDefaultIsolationScope } from '../defaultScopes';
import { Scope } from '../scope';
import type { Client } from '../types-hoist';
import { isThenable } from '../utils-hoist/is';
import { getMainCarrier, getSentryCarrier } from './../carrier';
import type { AsyncContextStrategy } from './types';
Expand Down
34 changes: 28 additions & 6 deletions packages/core/src/baseclient.ts → packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type {
Breadcrumb,
BreadcrumbHint,
Client,
CheckIn,
ClientOptions,
DataCategory,
DsnComponents,
Expand All @@ -15,6 +15,7 @@ import type {
EventProcessor,
FeedbackEvent,
Integration,
MonitorConfig,
Outcome,
ParameterizedString,
SdkMetadata,
Expand Down Expand Up @@ -71,7 +72,7 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
* without a valid Dsn, the SDK will not send any events to Sentry.
*
* Before sending an event, it is passed through
* {@link BaseClient._prepareEvent} to add SDK information and scope data
* {@link Client._prepareEvent} to add SDK information and scope data
* (breadcrumbs and context). To add more custom information, override this
* method and extend the resulting prepared event.
*
Expand All @@ -81,15 +82,15 @@ const MISSING_RELEASE_FOR_SESSION_ERROR = 'Discarded session because of missing
* {@link Client.addBreadcrumb}.
*
* @example
* class NodeClient extends BaseClient<NodeOptions> {
* class NodeClient extends Client<NodeOptions> {
* public constructor(options: NodeOptions) {
* super(options);
* }
*
* // ...
* }
*/
export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
export abstract class Client<O extends ClientOptions = ClientOptions> {
/** Options passed to the SDK. */
protected readonly _options: O;

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

/**
* Create a cron monitor check in and send it to Sentry. This method is not available on all clients.
*
* @param checkIn An object that describes a check in.
* @param upsertMonitorConfig An optional object that describes a monitor config. Use this if you want
* to create a monitor automatically when sending a check in.
* @param scope An optional scope containing event metadata.
* @returns A string representing the id of the check in.
*/
public captureCheckIn?(checkIn: CheckIn, monitorConfig?: MonitorConfig, scope?: Scope): string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we intentionally didn't add this to BaseClient, only to the ServerRuntimeClient so that check-in stays server-side specific.

Why did we make this change here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was in the type of Client. I merged this in as a type, but it is still optional! So not every client has to implement this method. I think that means nothing effectively should change?


/**
* @inheritDoc
*/
Expand Down Expand Up @@ -452,7 +464,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
/** @inheritdoc */
public on(
hook: 'beforeSendFeedback',
callback: (feedback: FeedbackEvent, options?: { includeReplay: boolean }) => void,
callback: (feedback: FeedbackEvent, options?: { includeReplay?: boolean }) => void,
): () => void;

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

/** @inheritdoc */
public emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay: boolean }): void;
public emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay?: boolean }): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this typed incorrectly before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! It differed between here and the type interface 😬


/** @inheritdoc */
public emit(
Expand Down Expand Up @@ -948,6 +960,16 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
): PromiseLike<Event>;
}

/**
* @deprecated Use `Client` instead. This alias may be removed in a future major version.
*/
export type BaseClient = Client;

/**
* @deprecated Use `Client` instead. This alias may be removed in a future major version.
*/
export const BaseClient = Client;

/**
* Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/currentScopes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getAsyncContextStrategy } from './asyncContext';
import { getGlobalSingleton, getMainCarrier } from './carrier';
import type { Client } from './client';
import { Scope } from './scope';
import type { Client, TraceContext } from './types-hoist';
import type { TraceContext } from './types-hoist';
import { dropUndefinedKeys } from './utils-hoist/object';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/envelope.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Client } from './client';
import { getDynamicSamplingContextFromSpan } from './tracing/dynamicSamplingContext';
import type { SentrySpan } from './tracing/sentrySpan';
import type {
Client,
DsnComponents,
DynamicSamplingContext,
Event,
Expand Down
9 changes: 4 additions & 5 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes';
import { DEBUG_BUILD } from './debug-build';
import type { CaptureContext } from './scope';
import { closeSession, makeSession, updateSession } from './session';
import type {
CheckIn,
Event,
Expand All @@ -13,11 +17,6 @@ import type {
SeverityLevel,
User,
} from './types-hoist';

import { getClient, getCurrentScope, getIsolationScope, withIsolationScope } from './currentScopes';
import { DEBUG_BUILD } from './debug-build';
import type { CaptureContext } from './scope';
import { closeSession, makeSession, updateSession } from './session';
import { isThenable } from './utils-hoist/is';
import { logger } from './utils-hoist/logger';
import { uuid4 } from './utils-hoist/misc';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Client } from './client';
import type { Scope } from './scope';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from './semanticAttributes';
import { SPAN_STATUS_ERROR, setHttpStatus, startInactiveSpan } from './tracing';
import { SentryNonRecordingSpan } from './tracing/sentryNonRecordingSpan';
import type { Client, HandlerDataFetch, Span, SpanOrigin } from './types-hoist';
import type { HandlerDataFetch, Span, SpanOrigin } from './types-hoist';
import { SENTRY_BAGGAGE_KEY_PREFIX } from './utils-hoist/baggage';
import { isInstanceOf } from './utils-hoist/is';
import { parseUrl } from './utils-hoist/url';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/getCurrentHubShim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { addBreadcrumb } from './breadcrumbs';
import type { Client } from './client';
import { getClient, getCurrentScope, getIsolationScope, withScope } from './currentScopes';
import {
captureEvent,
Expand All @@ -11,7 +12,7 @@ import {
setUser,
startSession,
} from './exports';
import type { Client, EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from './types-hoist';
import type { EventHint, Hub, Integration, IntegrationClass, SeverityLevel } from './types-hoist';

/**
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export { Scope } from './scope';
export type { CaptureContext, ScopeContext, ScopeData } from './scope';
export { notifyEventProcessors } from './eventProcessors';
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
export { BaseClient } from './baseclient';
export {
Client,
// eslint-disable-next-line deprecation/deprecation
BaseClient,
} from './client';
export { ServerRuntimeClient } from './server-runtime-client';
export { initAndBind, setCurrentClient } from './sdk';
export { createTransport } from './transports/base';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Client } from './client';
import { getClient } from './currentScopes';
import type { Client, Event, EventHint, Integration, IntegrationFn, Options } from './types-hoist';

import { DEBUG_BUILD } from './debug-build';
import type { Event, EventHint, Integration, IntegrationFn, Options } from './types-hoist';
import { logger } from './utils-hoist/logger';

export const installedIntegrations: string[] = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/integrations/functiontostring.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Client } from '../client';
import { getClient } from '../currentScopes';
import { defineIntegration } from '../integration';
import type { Client, IntegrationFn, WrappedFunction } from '../types-hoist';
import type { IntegrationFn, WrappedFunction } from '../types-hoist';
import { getOriginalFunction } from '../utils-hoist/object';

let originalFunctionToString: () => void;
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable max-lines */
import type { Client } from './client';
import { updateSession } from './session';
import type {
Attachment,
Breadcrumb,
Client,
Context,
Contexts,
Event,
Expand All @@ -17,8 +18,6 @@ import type {
Span,
User,
} from './types-hoist';

import { updateSession } from './session';
import { isPlainObject } from './utils-hoist/is';
import { logger } from './utils-hoist/logger';
import { uuid4 } from './utils-hoist/misc';
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Client } from './client';
import { getCurrentScope } from './currentScopes';
import type { Client, ClientOptions } from './types-hoist';

import { DEBUG_BUILD } from './debug-build';
import type { ClientOptions } from './types-hoist';
import { consoleSandbox, logger } from './utils-hoist/logger';

/** A class object that can instantiate Client objects. */
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import type {
TraceContext,
} from './types-hoist';

import { BaseClient } from './baseclient';
import { createCheckInEnvelope } from './checkin';
import { Client } from './client';
import { getIsolationScope, getTraceContextFromScope } from './currentScopes';
import { DEBUG_BUILD } from './debug-build';
import type { Scope } from './scope';
Expand All @@ -40,7 +40,7 @@ export interface ServerRuntimeClientOptions extends ClientOptions<BaseTransportO
*/
export class ServerRuntimeClient<
O extends ClientOptions & ServerRuntimeClientOptions = ServerRuntimeClientOptions,
> extends BaseClient<O> {
> extends Client<O> {
/**
* Creates a new Edge SDK instance.
* @param options Configuration options for this SDK.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function makeSession(context?: Omit<SessionContext, 'started' | 'status'>
* Note that this function mutates the passed object and returns void.
* (Had to do this instead of returning a new and updated session because closing and sending a session
* makes an update to the session after it was passed to the sending logic.
* @see BaseClient.captureSession )
* @see Client.captureSession )
*
* @param session the `Session` to update
* @param context the `SessionContext` holding the properties that should be updated in @param session
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tracing/dynamicSamplingContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Client, DynamicSamplingContext, Span } from '../types-hoist';

import type { Client } from '../client';
import { DEFAULT_ENVIRONMENT } from '../constants';
import { getClient } from '../currentScopes';
import type { Scope } from '../scope';
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
import type { DynamicSamplingContext, Span } from '../types-hoist';
import {
baggageHeaderToDynamicSamplingContext,
dynamicSamplingContextToSentryBaggageHeader,
Expand Down
Loading
Loading