Skip to content

ref: Remove the backend #4307

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

Closed
wants to merge 17 commits into from
Closed
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
77 changes: 0 additions & 77 deletions packages/browser/src/backend.ts

This file was deleted.

78 changes: 73 additions & 5 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
import { Event, EventHint } from '@sentry/types';
import { getGlobalObject, logger } from '@sentry/utils';
import { Event, EventHint, Options, SeverityLevel, Transport } from '@sentry/types';
import { getGlobalObject, logger, supportsFetch } from '@sentry/utils';

import { BrowserBackend, BrowserOptions } from './backend';
import { eventFromException, eventFromMessage } from './eventbuilder';
import { injectReportDialog, ReportDialogOptions } from './helpers';
import { Breadcrumbs } from './integrations';
import { FetchTransport, 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<string | RegExp>;

/**
* 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<string | RegExp>;

/** @deprecated use {@link Options.allowUrls} instead. */
whitelistUrls?: Array<string | RegExp>;

/** @deprecated use {@link Options.denyUrls} instead. */
blacklistUrls?: Array<string | RegExp>;
}

/**
* The Sentry Browser SDK Client.
*
* @see BrowserOptions for documentation on configuration options.
* @see SentryClient for usage documentation.
*/
export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
export class BrowserClient extends BaseClient<BrowserOptions> {
/**
* Creates a new Browser SDK instance.
*
Expand All @@ -31,7 +58,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
version: SDK_VERSION,
};

super(BrowserBackend, options);
super(options);
}

/**
Expand Down Expand Up @@ -75,4 +102,45 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
}
super._sendEvent(event);
}

/**
* @inheritDoc
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
protected _eventFromException(exception: any, hint?: EventHint): PromiseLike<Event> {
return eventFromException(this._options, exception, hint);
}

/**
* @inheritDoc
*/
protected _eventFromMessage(message: string, level: SeverityLevel = 'info', hint?: EventHint): PromiseLike<Event> {
return eventFromMessage(this._options, message, level, hint);
}

/**
* @inheritDoc
*/
protected _setupTransport(): Transport | undefined {
if (!this._options.dsn) {
// We return the noop transport here in case there is no Dsn.
return undefined;
}

const transportOptions = {
...this._options.transportOptions,
dsn: this._options.dsn,
tunnel: this._options.tunnel,
sendClientReports: this._options.sendClientReports,
_metadata: this._options._metadata,
};

if (this._options.transport) {
return new this._options.transport(transportOptions);
}
if (supportsFetch()) {
return new FetchTransport(transportOptions);
}
return new XHRTransport(transportOptions);
}
}
3 changes: 1 addition & 2 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export {
withScope,
} from '@sentry/core';

export { BrowserOptions } from './backend';
export { BrowserClient } from './client';
export { BrowserClient, BrowserOptions } from './client';
export { injectReportDialog, ReportDialogOptions } from './helpers';
export { eventFromException, eventFromMessage } from './eventbuilder';
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
import { addInstrumentationHandler, getGlobalObject, logger, resolvedSyncPromise } from '@sentry/utils';

import { BrowserOptions } from './backend';
import { BrowserClient } from './client';
import { BrowserClient, BrowserOptions } from './client';
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
import { Breadcrumbs, Dedupe, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';

Expand Down
12 changes: 0 additions & 12 deletions packages/browser/test/unit/backend.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/browser/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe('SentryBrowser initialization', () => {
it('should set SDK data when Sentry.init() is called', () => {
init({ dsn });

const sdkData = (getCurrentHub().getClient() as any)._backend._transport._api.metadata?.sdk;
const sdkData = (getCurrentHub().getClient() as any)._transport._api.metadata?.sdk;

expect(sdkData.name).toBe('sentry.javascript.browser');
expect(sdkData.packages[0].name).toBe('npm:@sentry/browser');
Expand All @@ -257,7 +257,7 @@ describe('SentryBrowser initialization', () => {
it('should set SDK data when instantiating a client directly', () => {
const client = new BrowserClient({ dsn });

const sdkData = (client as any)._backend._transport._api.metadata?.sdk;
const sdkData = (client as any)._transport._api.metadata?.sdk;

expect(sdkData.name).toBe('sentry.javascript.browser');
expect(sdkData.packages[0].name).toBe('npm:@sentry/browser');
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('SentryBrowser initialization', () => {
},
});

const sdkData = (getCurrentHub().getClient() as any)._backend._transport._api.metadata?.sdk;
const sdkData = (getCurrentHub().getClient() as any)._transport._api.metadata?.sdk;

expect(sdkData.name).toBe('sentry.javascript.angular');
expect(sdkData.packages[0].name).toBe('npm:@sentry/angular');
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/unit/integrations/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WrappedFunction } from '@sentry/types';
import { SinonSpy, spy } from 'sinon';
import { spy } from 'sinon';

import { wrap } from '../../../src/helpers';

Expand Down
11 changes: 4 additions & 7 deletions packages/browser/test/unit/integrations/linkederrors.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExtendedError } from '@sentry/types';

import { BrowserBackend } from '../../../src/backend';
import { eventFromException } from '../../../src';
import * as LinkedErrorsModule from '../../../src/integrations/linkederrors';

describe('LinkedErrors', () => {
Expand Down Expand Up @@ -34,8 +34,7 @@ describe('LinkedErrors', () => {
one.cause = two;

const originalException = one;
const backend = new BrowserBackend({});
return backend.eventFromException(originalException).then(event => {
return eventFromException({}, originalException).then(event => {
const result = LinkedErrorsModule._handler('cause', 5, event, {
originalException,
});
Expand Down Expand Up @@ -64,8 +63,7 @@ describe('LinkedErrors', () => {
one.reason = two;

const originalException = one;
const backend = new BrowserBackend({});
return backend.eventFromException(originalException).then(event => {
return eventFromException({}, originalException).then(event => {
const result = LinkedErrorsModule._handler('reason', 5, event, {
originalException,
});
Expand All @@ -90,9 +88,8 @@ describe('LinkedErrors', () => {
one.cause = two;
two.cause = three;

const backend = new BrowserBackend({});
const originalException = one;
return backend.eventFromException(originalException).then(event => {
return eventFromException({}, originalException).then(event => {
const result = LinkedErrorsModule._handler('cause', 2, event, {
originalException,
});
Expand Down
Loading