Skip to content

Commit 50b5a51

Browse files
committed
ref: Unify integrations options and set proper defaults
1 parent 4bb8be9 commit 50b5a51

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,42 @@ function addSentryBreadcrumb(serializedData: string): void {
4343
}
4444
}
4545

46+
/** JSDoc */
47+
interface BreadcrumbIntegrations {
48+
beacon?: boolean;
49+
console?: boolean;
50+
dom?: boolean;
51+
fetch?: boolean;
52+
history?: boolean;
53+
sentry?: boolean;
54+
xhr?: boolean;
55+
}
56+
4657
/** Default Breadcrumbs instrumentations */
4758
export class Breadcrumbs implements Integration {
4859
/**
4960
* @inheritDoc
5061
*/
5162
public name: string = 'Breadcrumbs';
5263

64+
/** JSDoc */
65+
private readonly options: BreadcrumbIntegrations;
66+
5367
/**
5468
* @inheritDoc
5569
*/
56-
public constructor(
57-
private readonly config: {
58-
beacon?: boolean;
59-
console?: boolean;
60-
dom?: boolean;
61-
fetch?: boolean;
62-
history?: boolean;
63-
sentry?: boolean;
64-
xhr?: boolean;
65-
} = {
70+
public constructor(options?: BreadcrumbIntegrations) {
71+
this.options = {
6672
beacon: true,
6773
console: true,
6874
dom: true,
6975
fetch: true,
7076
history: true,
7177
sentry: true,
7278
xhr: true,
73-
},
74-
) {}
79+
...options,
80+
};
81+
}
7582

7683
/** JSDoc */
7784
private instrumentBeacon(options: { filterUrl?: string }): void {
@@ -447,28 +454,26 @@ export class Breadcrumbs implements Integration {
447454
* - XMLHttpRequest API
448455
* - Fetch API
449456
* - History API
450-
*
451-
* Can be disabled or individually configured via the `autoBreadcrumbs` config option
452457
*/
453458
public install(options: BrowserOptions = {}): void {
454459
const filterUrl = options.dsn && new API(options.dsn).getStoreEndpoint();
455460

456-
if (this.config.console) {
461+
if (this.options.console) {
457462
this.instrumentConsole();
458463
}
459-
if (this.config.dom) {
464+
if (this.options.dom) {
460465
this.instrumentDOM();
461466
}
462-
if (this.config.xhr) {
467+
if (this.options.xhr) {
463468
this.instrumentXHR({ filterUrl });
464469
}
465-
if (this.config.fetch) {
470+
if (this.options.fetch) {
466471
this.instrumentFetch({ filterUrl });
467472
}
468-
if (this.config.beacon) {
473+
if (this.options.beacon) {
469474
this.instrumentBeacon({ filterUrl });
470475
}
471-
if (this.config.history) {
476+
if (this.options.history) {
472477
this.instrumentHistory();
473478
}
474479
}

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@ import {
99
} from '../tracekit';
1010
import { shouldIgnoreOnError } from './helpers';
1111

12+
/** JSDoc */
13+
interface GlobalHandlersIntegrations {
14+
onerror: boolean;
15+
onunhandledrejection: boolean;
16+
}
17+
1218
/** Global handlers */
1319
export class GlobalHandlers implements Integration {
1420
/**
1521
* @inheritDoc
1622
*/
1723
public name: string = 'GlobalHandlers';
18-
public constructor(
19-
private readonly options: {
20-
onerror: boolean;
21-
onunhandledrejection: boolean;
22-
} = {
24+
25+
/** JSDoc */
26+
private readonly options: GlobalHandlersIntegrations;
27+
28+
/** JSDoc */
29+
public constructor(options?: GlobalHandlersIntegrations) {
30+
this.options = {
2331
onerror: true,
2432
onunhandledrejection: true,
25-
},
26-
) {}
33+
...options,
34+
};
35+
}
2736
/**
2837
* @inheritDoc
2938
*/

packages/browser/src/integrations/reportingobserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ReportingObserver implements Integration {
6363
* @inheritDoc
6464
*/
6565
public constructor(
66-
private readonly config: {
66+
private readonly options: {
6767
types?: ReportTypes[];
6868
} = {
6969
types: [ReportTypes.Crash, ReportTypes.Deprecation, ReportTypes.Intervention],
@@ -82,7 +82,7 @@ export class ReportingObserver implements Integration {
8282
ReportingObserver: any;
8383
}).ReportingObserver(this.handler.bind(this), {
8484
buffered: true,
85-
types: this.config.types,
85+
types: this.options.types,
8686
});
8787

8888
observer.observe();

0 commit comments

Comments
 (0)