Skip to content

Commit 38e3379

Browse files
committed
Add sendClientReport option to disable sdk client reports
1 parent b87dc26 commit 38e3379

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

packages/browser/src/backend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
6262
...this._options.transportOptions,
6363
dsn: this._options.dsn,
6464
tunnel: this._options.tunnel,
65+
sendClientReports: this._options.sendClientReports,
6566
_metadata: this._options._metadata,
6667
};
6768

packages/browser/src/sdk.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export function init(options: BrowserOptions = {}): void {
8888
if (options.autoSessionTracking === undefined) {
8989
options.autoSessionTracking = true;
9090
}
91+
if (options.sendClientReports === undefined) {
92+
options.sendClientReports = true;
93+
}
9194

9295
initAndBind(BrowserClient, options);
9396

packages/browser/src/transports/base.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ export abstract class BaseTransport implements Transport {
4242
// eslint-disable-next-line deprecation/deprecation
4343
this.url = this._api.getStoreEndpointWithUrlEncodedAuth();
4444

45-
document.addEventListener('visibilitychange', () => {
46-
if (document.visibilityState === 'hidden') {
47-
this._flushOutcomes();
48-
}
49-
});
45+
if (this.options.sendClientReport) {
46+
document.addEventListener('visibilitychange', () => {
47+
if (document.visibilityState === 'hidden') {
48+
this._flushOutcomes();
49+
}
50+
});
51+
}
5052
}
5153

5254
/**
@@ -67,6 +69,10 @@ export abstract class BaseTransport implements Transport {
6769
* @inheritDoc
6870
*/
6971
public recordLostEvent(type: Outcome): void {
72+
if (!this.options.sendClientReport) {
73+
return;
74+
}
75+
7076
logger.log(`Adding ${type} outcome`);
7177
this._outcomes[type] = (this._outcomes[type] ?? 0) + 1;
7278
}
@@ -75,6 +81,10 @@ export abstract class BaseTransport implements Transport {
7581
* Send outcomes as an envelope
7682
*/
7783
protected _flushOutcomes(): void {
84+
if (!this.options.sendClientReport) {
85+
return;
86+
}
87+
7888
if (!navigator || typeof navigator.sendBeacon !== 'function') {
7989
logger.warn('Beacon API not available, skipping sending outcomes.');
8090
return;

packages/types/src/options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export interface Options {
132132
*/
133133
autoSessionTracking?: boolean;
134134

135+
/**
136+
* Automatically send SDK Client Report
137+
*/
138+
sendClientReports?: boolean;
139+
135140
/**
136141
* Initial data to populate scope.
137142
*/

packages/types/src/transport.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export interface TransportOptions {
6464
fetchParameters?: { [key: string]: string };
6565
/** The envelope tunnel to use. */
6666
tunnel?: string;
67+
/** Automatically send SDK Client Report */
68+
sendClientReport?: boolean;
6769
/**
6870
* Set of metadata about the SDK that can be internally used to enhance envelopes and events,
6971
* and provide additional data about every request.

0 commit comments

Comments
 (0)