Skip to content

Commit d47622c

Browse files
HazATkamilogorek
authored andcommitted
ref: Remove install function from client and backend (#1888)
1 parent 7f0ab14 commit d47622c

File tree

8 files changed

+5
-97
lines changed

8 files changed

+5
-97
lines changed

packages/browser/src/backend.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { BaseBackend, Options } from '@sentry/core';
22
import { SentryEvent, SentryEventHint, Severity, Transport } from '@sentry/types';
3-
import { SentryError } from '@sentry/utils/error';
43
import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is';
54
import { supportsBeacon, supportsFetch } from '@sentry/utils/supports';
65
import { SyncPromise } from '@sentry/utils/syncpromise';
@@ -33,23 +32,6 @@ export interface BrowserOptions extends Options {
3332
* @hidden
3433
*/
3534
export class BrowserBackend extends BaseBackend<BrowserOptions> {
36-
/**
37-
* @inheritDoc
38-
*/
39-
public install(): boolean {
40-
// We are only called by the client if the SDK is enabled and a valid Dsn
41-
// has been configured. If no Dsn is present, this indicates a programming
42-
// error.
43-
const dsn = this.options.dsn;
44-
if (!dsn) {
45-
throw new SentryError('Invariant exception: install() must not be called when disabled');
46-
}
47-
48-
Error.stackTraceLimit = 50;
49-
50-
return true;
51-
}
52-
5335
/**
5436
* @inheritdoc
5537
*/

packages/browser/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
4343
*
4444
* @param options Configuration options for this SDK.
4545
*/
46-
public constructor(options: BrowserOptions) {
46+
public constructor(options: BrowserOptions = {}) {
4747
super(BrowserBackend, options);
4848
}
4949

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export class GlobalHandlers implements Integration {
4545
* @inheritDoc
4646
*/
4747
public setupOnce(): void {
48+
Error.stackTraceLimit = 50;
49+
4850
subscribe((stack: TraceKitStackTrace, _: boolean, error: Error) => {
4951
// TODO: use stack.context to get a valuable information from TraceKit, eg.
5052
// [

packages/core/src/basebackend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export abstract class BaseBackend<O extends Options> implements Backend {
2222
/** Cached transport used internally. */
2323
protected transport: Transport;
2424

25-
/** Creates a new browser backend instance. */
25+
/** Creates a new backend instance. */
2626
public constructor(options: O) {
2727
this.options = options;
2828
if (!this.options.dsn) {

packages/core/src/baseclient.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
8484
*/
8585
private readonly dsn?: Dsn;
8686

87-
/**
88-
* Stores whether installation has been performed and was successful. Before
89-
* installing, this is undefined. Then it contains the success state.
90-
*/
91-
private installed?: boolean;
92-
9387
/** Array of used integrations. */
9488
private readonly integrations: IntegrationIndex;
9589

@@ -106,25 +100,8 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
106100
if (options.dsn) {
107101
this.dsn = new Dsn(options.dsn);
108102
}
109-
// We have to setup the integrations in the constructor since we do not want
110-
// that anyone needs to call client.install();
111-
this.integrations = setupIntegrations(this.options);
112-
}
113-
114-
/**
115-
* @inheritDoc
116-
*/
117-
public install(): boolean {
118-
if (!this.isEnabled()) {
119-
return (this.installed = false);
120-
}
121103

122-
const backend = this.getBackend();
123-
if (!this.installed && backend.install) {
124-
backend.install();
125-
}
126-
127-
return (this.installed = true);
104+
this.integrations = setupIntegrations(this.options);
128105
}
129106

130107
/**

packages/core/src/interfaces.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,6 @@ export interface Options {
145145
* captureMessage('Custom message');
146146
*/
147147
export interface Client<O extends Options = Options> {
148-
/**
149-
* Installs the SDK if it hasn't been installed already.
150-
*
151-
* Since this performs modifications in the environment, such as instrumenting
152-
* library functionality or adding signal handlers, this method will only
153-
* execute once and cache its result.
154-
*
155-
* @returns If the installation was the successful or not.
156-
*/
157-
install(): boolean;
158-
159148
/**
160149
* Captures an exception event and sends it to Sentry.
161150
*
@@ -240,9 +229,6 @@ export interface Client<O extends Options = Options> {
240229
* these any time and they should not be cached.
241230
*/
242231
export interface Backend {
243-
/** Installs the SDK into the environment. */
244-
install?(): boolean;
245-
246232
/** Creates a {@link SentryEvent} from an exception. */
247233
eventFromException(exception: any, hint?: SentryEventHint): SyncPromise<SentryEvent>;
248234

packages/core/src/sdk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ export function initAndBind<F extends Client, O extends Options>(clientClass: Cl
2626

2727
const client = new clientClass(options);
2828
getCurrentHub().bindClient(client);
29-
client.install();
3029
}

packages/core/test/lib/base.test.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,6 @@ describe('BaseClient', () => {
6262
});
6363
});
6464

65-
describe('install()', () => {
66-
test('calls install() on Backend', () => {
67-
expect.assertions(1);
68-
const client = new TestClient({ dsn: PUBLIC_DSN });
69-
client.install();
70-
expect(TestBackend.instance!.installed).toBe(1);
71-
});
72-
73-
test('calls install() only once', () => {
74-
expect.assertions(1);
75-
const client = new TestClient({ dsn: PUBLIC_DSN });
76-
client.install();
77-
client.install();
78-
expect(TestBackend.instance!.installed).toBe(1);
79-
});
80-
81-
test('resolves the result of install()', () => {
82-
expect.assertions(1);
83-
const client = new TestClient({ mockInstallFailure: true });
84-
const installed = client.install();
85-
expect(installed).toBeFalsy();
86-
});
87-
88-
test('does not install() when disabled', () => {
89-
expect.assertions(1);
90-
const client = new TestClient({ enabled: false, dsn: PUBLIC_DSN });
91-
client.install();
92-
expect(TestBackend.instance!.installed).toBe(0);
93-
});
94-
95-
test('does not install() without Dsn', () => {
96-
expect.assertions(1);
97-
const client = new TestClient({});
98-
client.install();
99-
expect(TestBackend.instance!.installed).toBe(0);
100-
});
101-
});
102-
10365
describe('getOptions()', () => {
10466
test('returns the options', () => {
10567
expect.assertions(1);

0 commit comments

Comments
 (0)