Skip to content

Commit 1d007e7

Browse files
committed
[v7] Remove Backend usage from the whole SDK architecture
1 parent de9b90d commit 1d007e7

File tree

22 files changed

+351
-504
lines changed

22 files changed

+351
-504
lines changed

packages/browser/src/backend.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

packages/browser/src/client.ts

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
2-
import { Event, EventHint } from '@sentry/types';
3-
import { getGlobalObject, logger } from '@sentry/utils';
4-
import { ReportDialogOptions } from '@sentry/transport-base';
2+
import { Event, EventHint, Options, Severity } from '@sentry/types';
3+
import { getGlobalObject, logger, supportsFetch } from '@sentry/utils';
4+
import { NoopTransport, ReportDialogOptions, Transport, TransportOptions } from '@sentry/transport-base';
5+
import { FetchTransport } from '@sentry/transport-fetch';
6+
import { XHRTransport } from '@sentry/transport-xhr';
57

6-
import { BrowserBackend, BrowserOptions } from './backend';
78
import { injectReportDialog } from './helpers';
89
import { Breadcrumbs } from './integrations';
10+
import { eventFromException, eventFromMessage } from './eventbuilder';
11+
12+
/**
13+
* Configuration options for the Sentry Browser SDK.
14+
* @see BrowserClient for more information.
15+
*/
16+
export interface BrowserOptions extends Options {
17+
/**
18+
* A pattern for error URLs which should exclusively be sent to Sentry.
19+
* This is the opposite of {@link Options.denyUrls}.
20+
* By default, all errors will be sent.
21+
*/
22+
allowUrls?: Array<string | RegExp>;
23+
24+
/**
25+
* A pattern for error URLs which should not be sent to Sentry.
26+
* To allow certain errors instead, use {@link Options.allowUrls}.
27+
* By default, all errors will be sent.
28+
*/
29+
denyUrls?: Array<string | RegExp>;
30+
31+
/** @deprecated use {@link Options.allowUrls} instead. */
32+
whitelistUrls?: Array<string | RegExp>;
33+
34+
/** @deprecated use {@link Options.denyUrls} instead. */
35+
blacklistUrls?: Array<string | RegExp>;
36+
37+
/**
38+
* A flag enabling Sessions Tracking feature.
39+
* By default Sessions Tracking is disabled.
40+
*/
41+
autoSessionTracking?: boolean;
42+
}
943

1044
/**
1145
* The Sentry Browser SDK Client.
1246
*
1347
* @see BrowserOptions for documentation on configuration options.
1448
* @see SentryClient for usage documentation.
1549
*/
16-
export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
50+
export class BrowserClient extends BaseClient<BrowserOptions> {
1751
/**
1852
* Creates a new Browser SDK instance.
1953
*
@@ -32,7 +66,20 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
3266
version: SDK_VERSION,
3367
};
3468

35-
super(BrowserBackend, options);
69+
super(options);
70+
}
71+
72+
/**
73+
* @inheritDoc
74+
*/
75+
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
76+
return eventFromException(this._options, exception, hint);
77+
}
78+
/**
79+
* @inheritDoc
80+
*/
81+
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
82+
return eventFromMessage(this._options, message, level, hint);
3683
}
3784

3885
/**
@@ -76,4 +123,26 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
76123
}
77124
super._sendEvent(event);
78125
}
126+
127+
protected _setupTransport(): Transport {
128+
// TODO: This whole function should be unnecessary and moved to client construction
129+
if (!this._options.dsn) {
130+
// We return the noop transport here in case there is no Dsn.
131+
return new NoopTransport();
132+
}
133+
134+
const transportOptions: TransportOptions = {
135+
...this._options.transportOptions,
136+
dsn: this._options.transportOptions?.dsn ?? this._options.dsn,
137+
};
138+
139+
if (this._options.transport) {
140+
return new this._options.transport(transportOptions);
141+
}
142+
143+
if (supportsFetch()) {
144+
return new FetchTransport(transportOptions);
145+
}
146+
return new XHRTransport(transportOptions);
147+
}
79148
}

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 { BrowserClient, BrowserOptions } from './client';
4342
export { injectReportDialog } 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
@@ -2,8 +2,7 @@ import { getCurrentHub, initAndBind, Integrations as CoreIntegrations } from '@s
22
import { addInstrumentationHandler, getGlobalObject, logger, SyncPromise } from '@sentry/utils';
33
import { ReportDialogOptions } from '@sentry/transport-base';
44

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

packages/browser/test/unit/backend.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/browser/test/unit/integrations/linkederrors.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { ExtendedError } from '@sentry/types';
1+
import { Event, ExtendedError } from '@sentry/types';
22
import { expect } from 'chai';
33
import { stub } from 'sinon';
44

5-
import { BrowserBackend } from '../../../src/backend';
65
import { LinkedErrors } from '../../../src/integrations/linkederrors';
76

7+
class BrowserBackend {
8+
eventFromException: (ex: unknown) => PromiseLike<Event> = () => Promise.resolve({});
9+
}
10+
811
// eslint-disable-next-line @typescript-eslint/no-explicit-any
912
let linkedErrors: any;
1013

@@ -62,7 +65,7 @@ describe('LinkedErrors', () => {
6265
one.cause = two;
6366

6467
const originalException = one;
65-
const backend = new BrowserBackend({});
68+
const backend = new BrowserBackend();
6669
return backend.eventFromException(originalException).then(event => {
6770
const result = linkedErrors._handler(event, {
6871
originalException,
@@ -96,7 +99,7 @@ describe('LinkedErrors', () => {
9699
one.reason = two;
97100

98101
const originalException = one;
99-
const backend = new BrowserBackend({});
102+
const backend = new BrowserBackend();
100103
return backend.eventFromException(originalException).then(event => {
101104
const result = linkedErrors._handler(event, {
102105
originalException,
@@ -126,7 +129,7 @@ describe('LinkedErrors', () => {
126129
one.cause = two;
127130
two.cause = three;
128131

129-
const backend = new BrowserBackend({});
132+
const backend = new BrowserBackend();
130133
return backend.eventFromException(one).then(event => {
131134
const result = linkedErrors._handler(event, {
132135
originalException: one,

packages/core/src/basebackend.ts

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)