From 1a52dd0b9e8594c89d84c434958d39e23a76909c Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 12 Apr 2022 13:35:33 +0200 Subject: [PATCH] ref(backend): Delete Backend classes (#4919) Delete the Backend classes. Specifically the following classes and files are removed: * `Backend (interface)` * `BaseBackend`* * `BrowserBackend` * `NodeBackend` * `TestBackend`* *`Options` interfaces in these files were moved to the respective Client files Additionally, * delete (the previously ported) `NoopTransport` test in packages/browser/test/unit/backend.test.ts. * adjust a few remaining Backend references in tests to use Client classes * adjust `BaseBackend` documentation to no longer include Backend information --- packages/browser/src/backend.ts | 83 --------- packages/browser/src/client.ts | 29 +++- packages/browser/src/exports.ts | 4 +- packages/browser/src/sdk.ts | 3 +- packages/browser/test/unit/backend.test.ts | 14 -- .../unit/integrations/linkederrors.test.ts | 17 +- packages/core/src/basebackend.ts | 161 ------------------ packages/core/src/baseclient.ts | 38 +---- packages/core/src/index.ts | 2 - packages/core/test/lib/base.test.ts | 2 +- packages/core/test/mocks/backend.ts | 72 -------- packages/core/test/mocks/client.ts | 7 +- packages/node/src/backend.ts | 69 -------- packages/node/src/client.ts | 8 +- packages/node/src/index.ts | 2 - .../test/integrations/linkederrors.test.ts | 28 ++- 16 files changed, 56 insertions(+), 483 deletions(-) delete mode 100644 packages/browser/src/backend.ts delete mode 100644 packages/browser/test/unit/backend.test.ts delete mode 100644 packages/core/src/basebackend.ts delete mode 100644 packages/core/test/mocks/backend.ts delete mode 100644 packages/node/src/backend.ts diff --git a/packages/browser/src/backend.ts b/packages/browser/src/backend.ts deleted file mode 100644 index 2543c6ae99ad..000000000000 --- a/packages/browser/src/backend.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { BaseBackend, getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails } from '@sentry/core'; -import { Event, EventHint, Options, Severity, Transport, TransportOptions } from '@sentry/types'; -import { supportsFetch } from '@sentry/utils'; - -import { eventFromException, eventFromMessage } from './eventbuilder'; -import { FetchTransport, makeNewFetchTransport, makeNewXHRTransport, XHRTransport } from './transports'; - -/** - * Configuration options for the Sentry Browser SDK. - * @see BrowserClient for more information. - * - * TODO(v7): move to client - */ -export interface BrowserOptions extends Options { - /** - * A pattern for error URLs which should exclusively be sent to Sentry. - * This is the opposite of {@link Options.denyUrls}. - * By default, all errors will be sent. - */ - allowUrls?: Array; - - /** - * A pattern for error URLs which should not be sent to Sentry. - * To allow certain errors instead, use {@link Options.allowUrls}. - * By default, all errors will be sent. - */ - denyUrls?: Array; -} - -/** - * The Sentry Browser SDK Backend. - * @hidden - */ -export class BrowserBackend extends BaseBackend { - /** - * @inheritDoc - */ - public eventFromException(exception: unknown, hint?: EventHint): PromiseLike { - return eventFromException(exception, hint, this._options.attachStacktrace); - } - /** - * @inheritDoc - */ - public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike { - return eventFromMessage(message, level, hint, this._options.attachStacktrace); - } - - /** - * @inheritDoc - */ - protected _setupTransport(): Transport { - if (!this._options.dsn) { - // We return the noop transport here in case there is no Dsn. - return super._setupTransport(); - } - - const transportOptions: TransportOptions = { - ...this._options.transportOptions, - dsn: this._options.dsn, - tunnel: this._options.tunnel, - sendClientReports: this._options.sendClientReports, - _metadata: this._options._metadata, - }; - - const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel); - const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel); - - if (this._options.transport) { - return new this._options.transport(transportOptions); - } - if (supportsFetch()) { - const requestOptions: RequestInit = { ...transportOptions.fetchParameters }; - this._newTransport = makeNewFetchTransport({ requestOptions, url }); - return new FetchTransport(transportOptions); - } - - this._newTransport = makeNewXHRTransport({ - url, - headers: transportOptions.headers, - }); - return new XHRTransport(transportOptions); - } -} diff --git a/packages/browser/src/client.ts b/packages/browser/src/client.ts index b64997c0a23b..8265889e4967 100644 --- a/packages/browser/src/client.ts +++ b/packages/browser/src/client.ts @@ -1,22 +1,40 @@ import { BaseClient, getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails, Scope, SDK_VERSION } from '@sentry/core'; -import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types'; +import { Event, EventHint, Options, Severity, Transport, TransportOptions } from '@sentry/types'; import { getGlobalObject, logger, supportsFetch } from '@sentry/utils'; -import { BrowserBackend, BrowserOptions } from './backend'; import { eventFromException, eventFromMessage } from './eventbuilder'; import { IS_DEBUG_BUILD } from './flags'; import { injectReportDialog, ReportDialogOptions } from './helpers'; import { Breadcrumbs } from './integrations'; import { FetchTransport, makeNewFetchTransport, makeNewXHRTransport, XHRTransport } from './transports'; +/** + * Configuration options for the Sentry Browser SDK. + * @see BrowserClient for more information. + */ +export interface BrowserOptions extends Options { + /** + * A pattern for error URLs which should exclusively be sent to Sentry. + * This is the opposite of {@link Options.denyUrls}. + * By default, all errors will be sent. + */ + allowUrls?: Array; + + /** + * A pattern for error URLs which should not be sent to Sentry. + * To allow certain errors instead, use {@link Options.allowUrls}. + * By default, all errors will be sent. + */ + denyUrls?: Array; +} + /** * The Sentry Browser SDK Client. * * @see BrowserOptions for documentation on configuration options. * @see SentryClient for usage documentation. - * TODO(v7): remove BrowserBackend */ -export class BrowserClient extends BaseClient { +export class BrowserClient extends BaseClient { /** * Creates a new Browser SDK instance. * @@ -35,8 +53,7 @@ export class BrowserClient extends BaseClient { version: SDK_VERSION, }; - // TODO(v7): remove BrowserBackend param - super(BrowserBackend, options); + super(options); } /** diff --git a/packages/browser/src/exports.ts b/packages/browser/src/exports.ts index 2a62e8e46fbe..6204a25f614e 100644 --- a/packages/browser/src/exports.ts +++ b/packages/browser/src/exports.ts @@ -41,9 +41,7 @@ export { withScope, } from '@sentry/core'; -// TODO(v7): refactor to use client here! -export { BrowserOptions } from './backend'; -export { BrowserClient } from './client'; +export { BrowserClient, BrowserOptions } from './client'; export { injectReportDialog, ReportDialogOptions } from './helpers'; export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk'; export { SDK_NAME } from './version'; diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 3f05a646c96f..44d66add18c3 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -2,8 +2,7 @@ import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@s import { Hub } from '@sentry/types'; import { addInstrumentationHandler, getGlobalObject, logger, resolvedSyncPromise } from '@sentry/utils'; -import { BrowserOptions } from './backend'; -import { BrowserClient } from './client'; +import { BrowserClient, BrowserOptions } from './client'; import { IS_DEBUG_BUILD } from './flags'; import { ReportDialogOptions, wrap as internalWrap } from './helpers'; import { Breadcrumbs, Dedupe, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations'; diff --git a/packages/browser/test/unit/backend.test.ts b/packages/browser/test/unit/backend.test.ts deleted file mode 100644 index 83f95307a8c7..000000000000 --- a/packages/browser/test/unit/backend.test.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BrowserBackend } from '../../src/backend'; - -let backend: BrowserBackend; - -// TODO(v7): remove when deleting Backend - -describe('BrowserBackend', () => { - describe('sendEvent()', () => { - it('should use NoopTransport', () => { - backend = new BrowserBackend({}); - expect(backend.getTransport().constructor.name).toBe('NoopTransport'); - }); - }); -}); diff --git a/packages/browser/test/unit/integrations/linkederrors.test.ts b/packages/browser/test/unit/integrations/linkederrors.test.ts index 35f54f4b2d87..8178741d1210 100644 --- a/packages/browser/test/unit/integrations/linkederrors.test.ts +++ b/packages/browser/test/unit/integrations/linkederrors.test.ts @@ -1,6 +1,6 @@ import { ExtendedError } from '@sentry/types'; -import { BrowserBackend } from '../../../src/backend'; +import { BrowserClient } from '../../../src/client'; import * as LinkedErrorsModule from '../../../src/integrations/linkederrors'; describe('LinkedErrors', () => { @@ -34,9 +34,8 @@ describe('LinkedErrors', () => { one.cause = two; const originalException = one; - // TODO(v7): refactor to use client here! - const backend = new BrowserBackend({}); - return backend.eventFromException(originalException).then(event => { + const client = new BrowserClient({}); + return client.eventFromException(originalException).then(event => { const result = LinkedErrorsModule._handler('cause', 5, event, { originalException, }); @@ -65,9 +64,8 @@ describe('LinkedErrors', () => { one.reason = two; const originalException = one; - const backend = new BrowserBackend({}); - // TODO(v7): refactor to use client here! - return backend.eventFromException(originalException).then(event => { + const client = new BrowserClient({}); + return client.eventFromException(originalException).then(event => { const result = LinkedErrorsModule._handler('reason', 5, event, { originalException, }); @@ -92,10 +90,9 @@ describe('LinkedErrors', () => { one.cause = two; two.cause = three; - const backend = new BrowserBackend({}); + const client = new BrowserClient({}); const originalException = one; - // TODO(v7): refactor to use client here! - return backend.eventFromException(originalException).then(event => { + return client.eventFromException(originalException).then(event => { const result = LinkedErrorsModule._handler('cause', 2, event, { originalException, }); diff --git a/packages/core/src/basebackend.ts b/packages/core/src/basebackend.ts deleted file mode 100644 index 92bdd4e7f65c..000000000000 --- a/packages/core/src/basebackend.ts +++ /dev/null @@ -1,161 +0,0 @@ -import { Event, EventHint, Options, Session, Severity, Transport } from '@sentry/types'; -import { logger, SentryError } from '@sentry/utils'; - -import { initAPIDetails } from './api'; -import { IS_DEBUG_BUILD } from './flags'; -import { createEventEnvelope, createSessionEnvelope } from './request'; -import { NewTransport } from './transports/base'; -import { NoopTransport } from './transports/noop'; - -/** - * Internal platform-dependent Sentry SDK Backend. - * - * While {@link Client} contains business logic specific to an SDK, the - * Backend offers platform specific implementations for low-level operations. - * These are persisting and loading information, sending events, and hooking - * into the environment. - * - * Backends receive a handle to the Client in their constructor. When a - * Backend automatically generates events, it must pass them to - * the Client for validation and processing first. - * - * Usually, the Client will be of corresponding type, e.g. NodeBackend - * receives NodeClient. However, higher-level SDKs can choose to instantiate - * multiple Backends and delegate tasks between them. In this case, an event - * generated by one backend might very well be sent by another one. - * - * The client also provides access to options via {@link Client.getOptions}. - * @hidden - */ -export interface Backend { - /** Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - eventFromException(exception: any, hint?: EventHint): PromiseLike; - - /** Creates an {@link Event} from primitive inputs to `captureMessage`. */ - eventFromMessage(message: string, level?: Severity, hint?: EventHint): PromiseLike; - - /** Submits the event to Sentry */ - sendEvent(event: Event): void; - - /** Submits the session to Sentry */ - sendSession(session: Session): void; - - /** - * Returns the transport that is used by the backend. - * Please note that the transport gets lazy initialized so it will only be there once the first event has been sent. - * - * @returns The transport. - */ - getTransport(): Transport; -} - -/** - * A class object that can instantiate Backend objects. - * @hidden - */ -export type BackendClass = new (options: O) => B; - -/** - * This is the base implemention of a Backend. - * @hidden - */ -export abstract class BaseBackend implements Backend { - /** Options passed to the SDK. */ - protected readonly _options: O; - - /** Cached transport used internally. */ - protected _transport: Transport; - - /** New v7 Transport that is initialized alongside the old one */ - protected _newTransport?: NewTransport; - - /** Creates a new backend instance. */ - public constructor(options: O) { - this._options = options; - if (!this._options.dsn) { - IS_DEBUG_BUILD && logger.warn('No DSN provided, backend will not do anything.'); - } - this._transport = this._setupTransport(); - } - - /** - * @inheritDoc - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types - public eventFromException(_exception: any, _hint?: EventHint): PromiseLike { - throw new SentryError('Backend has to implement `eventFromException` method'); - } - - /** - * @inheritDoc - */ - public eventFromMessage(_message: string, _level?: Severity, _hint?: EventHint): PromiseLike { - throw new SentryError('Backend has to implement `eventFromMessage` method'); - } - - /** - * @inheritDoc - */ - public sendEvent(event: Event): void { - // TODO(v7): Remove the if-else - if ( - this._newTransport && - this._options.dsn && - this._options._experiments && - this._options._experiments.newTransport - ) { - const api = initAPIDetails(this._options.dsn, this._options._metadata, this._options.tunnel); - const env = createEventEnvelope(event, api); - void this._newTransport.send(env).then(null, reason => { - IS_DEBUG_BUILD && logger.error('Error while sending event:', reason); - }); - } else { - void this._transport.sendEvent(event).then(null, reason => { - IS_DEBUG_BUILD && logger.error('Error while sending event:', reason); - }); - } - } - - /** - * @inheritDoc - */ - public sendSession(session: Session): void { - if (!this._transport.sendSession) { - IS_DEBUG_BUILD && logger.warn("Dropping session because custom transport doesn't implement sendSession"); - return; - } - - // TODO(v7): Remove the if-else - if ( - this._newTransport && - this._options.dsn && - this._options._experiments && - this._options._experiments.newTransport - ) { - const api = initAPIDetails(this._options.dsn, this._options._metadata, this._options.tunnel); - const [env] = createSessionEnvelope(session, api); - void this._newTransport.send(env).then(null, reason => { - IS_DEBUG_BUILD && logger.error('Error while sending session:', reason); - }); - } else { - void this._transport.sendSession(session).then(null, reason => { - IS_DEBUG_BUILD && logger.error('Error while sending session:', reason); - }); - } - } - - /** - * @inheritDoc - */ - public getTransport(): Transport { - return this._transport; - } - - /** - * Sets up the transport so it can be used later to send requests. - */ - protected _setupTransport(): Transport { - return new NoopTransport(); - } -} diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 59145508ca9d..75712f62479b 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -29,7 +29,6 @@ import { } from '@sentry/utils'; import { initAPIDetails } from './api'; -import { Backend, BackendClass } from './basebackend'; import { IS_DEBUG_BUILD } from './flags'; import { IntegrationIndex, setupIntegrations } from './integration'; import { createEventEnvelope, createSessionEnvelope } from './request'; @@ -41,19 +40,16 @@ const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been ca /** * Base implementation for all JavaScript SDK clients. * - * TODO(v7): refactor doc w.r.t. Backend - * - * Call the constructor with the corresponding backend constructor and options + * Call the constructor with the corresponding options * specific to the client subclass. To access these options later, use - * {@link Client.getOptions}. Also, the Backend instance is available via - * {@link Client.getBackend}. + * {@link Client.getOptions}. * * If a Dsn is specified in the options, it will be parsed and stored. Use * {@link Client.getDsn} to retrieve the Dsn at any moment. In case the Dsn is * invalid, the constructor will throw a {@link SentryException}. Note that * without a valid Dsn, the SDK will not send any events to Sentry. * - * Before sending an event via the backend, it is passed through + * Before sending an event, it is passed through * {@link BaseClient._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. @@ -64,23 +60,15 @@ const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been ca * {@link Client.addBreadcrumb}. * * @example - * class NodeClient extends BaseClient { + * class NodeClient extends BaseClient { * public constructor(options: NodeOptions) { - * super(NodeBackend, options); + * super(options); * } * * // ... * } */ -export abstract class BaseClient implements Client { - /** - * The backend used to physically interact in the environment. Usually, this - * will correspond to the client. When composing SDKs, however, the Backend - * from the root SDK will be used. - * TODO(v7): DELETE - */ - protected readonly _backend: B; - +export abstract class BaseClient implements Client { /** Options passed to the SDK. */ protected readonly _options: O; @@ -102,12 +90,9 @@ export abstract class BaseClient implement /** * Initializes this client instance. * - * @param backendClass A constructor function to create the backend. * @param options Options for the client. */ - protected constructor(backendClass: BackendClass, options: O) { - // TODO(v7): Delete - this._backend = new backendClass(options); + protected constructor(options: O) { this._options = options; if (options.dsn) { @@ -386,13 +371,6 @@ export abstract class BaseClient implement }); } - /** Returns the current backend. - * TODO(v7): DELETE - */ - protected _getBackend(): B { - return this._backend; - } - /** Determines whether this SDK is enabled and a valid Dsn is present. */ protected _isEnabled(): boolean { return this.getOptions().enabled !== false && this._dsn !== undefined; @@ -558,7 +536,7 @@ export abstract class BaseClient implement } /** - * Tells the backend to send this event + * Sends the passed event * @param event The Sentry event to send */ // TODO(v7): refactor: get rid of method? diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 77018c2b4437..e4143f098e4a 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -23,8 +23,6 @@ export { getReportDialogEndpoint, } from './api'; export { BaseClient } from './baseclient'; -// TODO(v7): Delete! -export { BackendClass, BaseBackend } from './basebackend'; export { eventToSentryRequest, sessionToSentryRequest } from './request'; export { initAndBind, ClientClass } from './sdk'; export { NoopTransport } from './transports/noop'; diff --git a/packages/core/test/lib/base.test.ts b/packages/core/test/lib/base.test.ts index 8a26bd51f116..6bb72ed99f16 100644 --- a/packages/core/test/lib/base.test.ts +++ b/packages/core/test/lib/base.test.ts @@ -898,7 +898,7 @@ describe('BaseClient', () => { } expect(capturedEvent).toEqual(normalizedTransaction); - // expect(TestBackend.instance!.event!).toEqual(normalizedTransaction); + // expect(TestClient.instance!.event!).toEqual(normalizedTransaction); }); test('calls beforeSend and uses original event without any changes', () => { diff --git a/packages/core/test/mocks/backend.ts b/packages/core/test/mocks/backend.ts deleted file mode 100644 index a201bc8c0b68..000000000000 --- a/packages/core/test/mocks/backend.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { Session } from '@sentry/hub'; -import { Event, Severity, Transport } from '@sentry/types'; -import { resolvedSyncPromise } from '@sentry/utils'; - -import { BaseBackend } from '../../src/basebackend'; -import { TestOptions } from './client'; - -// TODO: Delete whole file (?) - -export class TestBackend extends BaseBackend { - public static instance?: TestBackend; - public static sendEventCalled?: (event: Event) => void; - - public event?: Event; - public session?: Session; - - public constructor(protected readonly _options: TestOptions) { - super(_options); - TestBackend.instance = this; - } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types - public eventFromException(exception: any): PromiseLike { - return resolvedSyncPromise({ - exception: { - values: [ - { - /* eslint-disable @typescript-eslint/no-unsafe-member-access */ - type: exception.name, - value: exception.message, - /* eslint-enable @typescript-eslint/no-unsafe-member-access */ - }, - ], - }, - }); - } - - public eventFromMessage(message: string, level: Severity = Severity.Info): PromiseLike { - return resolvedSyncPromise({ message, level }); - } - - public sendEvent(event: Event): void { - this.event = event; - if (this._options.enableSend) { - super.sendEvent(event); - return; - } - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - TestBackend.sendEventCalled && TestBackend.sendEventCalled(event); - } - - public sendSession(session: Session): void { - this.session = session; - } - - protected _setupTransport(): Transport { - if (!this._options.dsn) { - // We return the noop transport here in case there is no Dsn. - return super._setupTransport(); - } - - const transportOptions = this._options.transportOptions - ? this._options.transportOptions - : { dsn: this._options.dsn }; - - if (this._options.transport) { - return new this._options.transport(transportOptions); - } - - return super._setupTransport(); - } -} diff --git a/packages/core/test/mocks/client.ts b/packages/core/test/mocks/client.ts index 8c02ca30f5f3..f399c6018122 100644 --- a/packages/core/test/mocks/client.ts +++ b/packages/core/test/mocks/client.ts @@ -4,15 +4,13 @@ import { resolvedSyncPromise } from '@sentry/utils'; import { BaseClient } from '../../src/baseclient'; import { initAndBind } from '../../src/sdk'; -import { TestBackend } from './backend'; export interface TestOptions extends Options { test?: boolean; mockInstallFailure?: boolean; enableSend?: boolean; } -// TODO(v7): remove TestBackend -export class TestClient extends BaseClient { +export class TestClient extends BaseClient { public static instance?: TestClient; public static sendEventCalled?: (event: Event) => void; @@ -20,8 +18,7 @@ export class TestClient extends BaseClient { public session?: Session; public constructor(options: TestOptions) { - // TODO(v7): remove TestBackend param - super(TestBackend, options); + super(options); TestClient.instance = this; } diff --git a/packages/node/src/backend.ts b/packages/node/src/backend.ts deleted file mode 100644 index f319673ebc18..000000000000 --- a/packages/node/src/backend.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { BaseBackend, getEnvelopeEndpointWithUrlEncodedAuth, initAPIDetails } from '@sentry/core'; -import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types'; -import { makeDsn, resolvedSyncPromise } from '@sentry/utils'; - -import { eventFromMessage, eventFromUnknownInput } from './eventbuilder'; -import { HTTPSTransport, HTTPTransport, makeNodeTransport } from './transports'; -import { NodeOptions } from './types'; - -/** - * The Sentry Node SDK Backend. - * @hidden - */ -export class NodeBackend extends BaseBackend { - /** - * @inheritDoc - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types - public eventFromException(exception: any, hint?: EventHint): PromiseLike { - return resolvedSyncPromise(eventFromUnknownInput(exception, hint)); - } - - /** - * @inheritDoc - */ - public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike { - return resolvedSyncPromise(eventFromMessage(message, level, hint, this._options.attachStacktrace)); - } - - /** - * @inheritDoc - */ - protected _setupTransport(): Transport { - if (!this._options.dsn) { - // We return the noop transport here in case there is no Dsn. - return super._setupTransport(); - } - - const dsn = makeDsn(this._options.dsn); - - const transportOptions: TransportOptions = { - ...this._options.transportOptions, - ...(this._options.httpProxy && { httpProxy: this._options.httpProxy }), - ...(this._options.httpsProxy && { httpsProxy: this._options.httpsProxy }), - ...(this._options.caCerts && { caCerts: this._options.caCerts }), - dsn: this._options.dsn, - tunnel: this._options.tunnel, - _metadata: this._options._metadata, - }; - - if (this._options.transport) { - return new this._options.transport(transportOptions); - } - - const api = initAPIDetails(transportOptions.dsn, transportOptions._metadata, transportOptions.tunnel); - const url = getEnvelopeEndpointWithUrlEncodedAuth(api.dsn, api.tunnel); - - this._newTransport = makeNodeTransport({ - url, - headers: transportOptions.headers, - proxy: transportOptions.httpProxy, - caCerts: transportOptions.caCerts, - }); - - if (dsn.protocol === 'http') { - return new HTTPTransport(transportOptions); - } - return new HTTPSTransport(transportOptions); - } -} diff --git a/packages/node/src/client.ts b/packages/node/src/client.ts index 0b2b585edc5d..4401f4016520 100644 --- a/packages/node/src/client.ts +++ b/packages/node/src/client.ts @@ -3,7 +3,6 @@ import { SessionFlusher } from '@sentry/hub'; import { Event, EventHint, Severity, Transport, TransportOptions } from '@sentry/types'; import { logger, makeDsn, resolvedSyncPromise } from '@sentry/utils'; -import { NodeBackend } from './backend'; import { eventFromMessage, eventFromUnknownInput } from './eventbuilder'; import { IS_DEBUG_BUILD } from './flags'; import { HTTPSTransport, HTTPTransport, makeNodeTransport } from './transports'; @@ -14,10 +13,8 @@ import { NodeOptions } from './types'; * * @see NodeOptions for documentation on configuration options. * @see SentryClient for usage documentation. - * - * TODO(v7): remove NodeBackend */ -export class NodeClient extends BaseClient { +export class NodeClient extends BaseClient { protected _sessionFlusher: SessionFlusher | undefined; /** @@ -37,8 +34,7 @@ export class NodeClient extends BaseClient { version: SDK_VERSION, }; - // TODO(v7): remove NodeBackend param - super(NodeBackend, options); + super(options); } /** diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 48bb88a24872..591fd4ad911d 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -42,8 +42,6 @@ export { } from '@sentry/core'; export { NodeOptions } from './types'; -// TODO(v7): delete! -export { NodeBackend } from './backend'; export { NodeClient } from './client'; export { defaultIntegrations, init, lastEventId, flush, close, getSentryRelease } from './sdk'; export { deepReadDirSync } from './utils'; diff --git a/packages/node/test/integrations/linkederrors.test.ts b/packages/node/test/integrations/linkederrors.test.ts index 8363bd177359..47249d129716 100644 --- a/packages/node/test/integrations/linkederrors.test.ts +++ b/packages/node/test/integrations/linkederrors.test.ts @@ -1,7 +1,6 @@ import { ExtendedError } from '@sentry/types'; -import { Event } from '../../src'; -import { NodeBackend } from '../../src/backend'; +import { Event, NodeClient } from '../../src'; import { LinkedErrors } from '../../src/integrations/linkederrors'; let linkedErrors: any; @@ -28,10 +27,9 @@ describe('LinkedErrors', () => { expect.assertions(2); const spy = jest.spyOn(linkedErrors, '_walkErrorTree'); const one = new Error('originalException'); - // TODO(v7): refactor to use client here! - const backend = new NodeBackend({}); + const client = new NodeClient({}); let event: Event | undefined; - return backend + return client .eventFromException(one) .then(eventFromException => { event = eventFromException; @@ -52,9 +50,8 @@ describe('LinkedErrors', () => { }), ); const one = new Error('originalException'); - const backend = new NodeBackend({}); - // TODO(v7): refactor to use client here! - return backend.eventFromException(one).then(event => + const client = new NodeClient({}); + return client.eventFromException(one).then(event => linkedErrors ._handler(event, { originalException: one, @@ -73,9 +70,8 @@ describe('LinkedErrors', () => { one.cause = two; two.cause = three; - const backend = new NodeBackend({}); - // TODO(v7): refactor to use client here! - return backend.eventFromException(one).then(event => + const client = new NodeClient({}); + return client.eventFromException(one).then(event => linkedErrors ._handler(event, { originalException: one, @@ -107,9 +103,8 @@ describe('LinkedErrors', () => { one.reason = two; two.reason = three; - const backend = new NodeBackend({}); - // TODO(v7): refactor to use client here! - return backend.eventFromException(one).then(event => + const client = new NodeClient({}); + return client.eventFromException(one).then(event => linkedErrors ._handler(event, { originalException: one, @@ -141,9 +136,8 @@ describe('LinkedErrors', () => { one.cause = two; two.cause = three; - const backend = new NodeBackend({}); - // TODO(v7): refactor to use client here! - return backend.eventFromException(one).then(event => + const client = new NodeClient({}); + return client.eventFromException(one).then(event => linkedErrors ._handler(event, { originalException: one,