Skip to content

Commit 442f60e

Browse files
committed
ref(browser): Remove backend
1 parent 5e7de88 commit 442f60e

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

packages/browser/src/client.ts

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
2-
import { Event, EventHint } from '@sentry/types';
3-
import { getGlobalObject, logger } from '@sentry/utils';
2+
import { Event, EventHint, Options, Severity, Transport } from '@sentry/types';
3+
import { getGlobalObject, logger, supportsFetch } from '@sentry/utils';
44

5-
import { BrowserBackend, BrowserOptions } from './backend';
5+
import { eventFromException, eventFromMessage } from './eventbuilder';
66
import { injectReportDialog, ReportDialogOptions } from './helpers';
77
import { Breadcrumbs } from './integrations';
8+
import { FetchTransport, XHRTransport } from './transports';
9+
10+
/**
11+
* Configuration options for the Sentry Browser SDK.
12+
* @see BrowserClient for more information.
13+
*/
14+
export interface BrowserOptions extends Options {
15+
/**
16+
* A pattern for error URLs which should exclusively be sent to Sentry.
17+
* This is the opposite of {@link Options.denyUrls}.
18+
* By default, all errors will be sent.
19+
*/
20+
allowUrls?: Array<string | RegExp>;
21+
22+
/**
23+
* A pattern for error URLs which should not be sent to Sentry.
24+
* To allow certain errors instead, use {@link Options.allowUrls}.
25+
* By default, all errors will be sent.
26+
*/
27+
denyUrls?: Array<string | RegExp>;
28+
29+
/** @deprecated use {@link Options.allowUrls} instead. */
30+
whitelistUrls?: Array<string | RegExp>;
31+
32+
/** @deprecated use {@link Options.denyUrls} instead. */
33+
blacklistUrls?: Array<string | RegExp>;
34+
}
835

936
/**
1037
* The Sentry Browser SDK Client.
1138
*
1239
* @see BrowserOptions for documentation on configuration options.
1340
* @see SentryClient for usage documentation.
1441
*/
15-
export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
42+
export class BrowserClient extends BaseClient<BrowserOptions> {
1643
/**
1744
* Creates a new Browser SDK instance.
1845
*
@@ -31,7 +58,21 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
3158
version: SDK_VERSION,
3259
};
3360

34-
super(BrowserBackend, options);
61+
super(options);
62+
}
63+
64+
/**
65+
* @inheritDoc
66+
*/
67+
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
68+
return eventFromException(this._options, exception, hint);
69+
}
70+
71+
/**
72+
* @inheritDoc
73+
*/
74+
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
75+
return eventFromMessage(this._options, message, level, hint);
3576
}
3677

3778
/**
@@ -57,6 +98,17 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5798
});
5899
}
59100

101+
/**
102+
* @inheritDoc
103+
*/
104+
public sendEvent(event: Event): void {
105+
const integration = this.getIntegration(Breadcrumbs);
106+
if (integration) {
107+
integration.addSentryBreadcrumb(event);
108+
}
109+
super.sendEvent(event);
110+
}
111+
60112
/**
61113
* @inheritDoc
62114
*/
@@ -68,11 +120,26 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
68120
/**
69121
* @inheritDoc
70122
*/
71-
protected _sendEvent(event: Event): void {
72-
const integration = this.getIntegration(Breadcrumbs);
73-
if (integration) {
74-
integration.addSentryBreadcrumb(event);
123+
protected _setupTransport(): Transport {
124+
if (!this._options.dsn) {
125+
// We return the noop transport here in case there is no Dsn.
126+
return super._setupTransport();
127+
}
128+
129+
const transportOptions = {
130+
...this._options.transportOptions,
131+
dsn: this._options.dsn,
132+
tunnel: this._options.tunnel,
133+
sendClientReports: this._options.sendClientReports,
134+
_metadata: this._options._metadata,
135+
};
136+
137+
if (this._options.transport) {
138+
return new this._options.transport(transportOptions);
139+
}
140+
if (supportsFetch()) {
141+
return new FetchTransport(transportOptions);
75142
}
76-
super._sendEvent(event);
143+
return new XHRTransport(transportOptions);
77144
}
78145
}

packages/browser/src/exports.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export {
3838
withScope,
3939
} from '@sentry/core';
4040

41-
export { BrowserOptions } from './backend';
42-
export { BrowserClient } from './client';
41+
export { BrowserOptions, BrowserClient } from './client';
4342
export { injectReportDialog, ReportDialogOptions } from './helpers';
4443
export { eventFromException, eventFromMessage } from './eventbuilder';
4544
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';

packages/browser/src/sdk.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
22
import { addInstrumentationHandler, getGlobalObject, logger, resolvedSyncPromise } from '@sentry/utils';
33

4-
import { BrowserOptions } from './backend';
5-
import { BrowserClient } from './client';
4+
import { BrowserClient, BrowserOptions } from './client';
65
import { ReportDialogOptions, wrap as internalWrap } from './helpers';
76
import { Breadcrumbs, Dedupe, GlobalHandlers, LinkedErrors, TryCatch, UserAgent } from './integrations';
87

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export {
2525
getReportDialogEndpoint,
2626
} from './api';
2727
export { BaseClient } from './baseclient';
28-
export { BackendClass, BaseBackend } from './basebackend';
2928
export { eventToSentryRequest, sessionToSentryRequest } from './request';
3029
export { initAndBind, ClientClass } from './sdk';
3130
export { NoopTransport } from './transports/noop';

0 commit comments

Comments
 (0)