Skip to content

Commit

Permalink
Add sendClientReport option to disable sdk client reports
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Sep 7, 2021
1 parent 3f2d081 commit 498fa19
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/browser/src/backend.ts
Expand Up @@ -62,6 +62,7 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
...this._options.transportOptions,
dsn: this._options.dsn,
tunnel: this._options.tunnel,
sendClientReports: this._options.sendClientReports,
_metadata: this._options._metadata,
};

Expand Down
3 changes: 3 additions & 0 deletions packages/browser/src/sdk.ts
Expand Up @@ -88,6 +88,9 @@ export function init(options: BrowserOptions = {}): void {
if (options.autoSessionTracking === undefined) {
options.autoSessionTracking = true;
}
if (options.sendClientReports === undefined) {
options.sendClientReports = true;
}

initAndBind(BrowserClient, options);

Expand Down
8 changes: 8 additions & 0 deletions packages/browser/src/transports/base.ts
Expand Up @@ -67,6 +67,10 @@ export abstract class BaseTransport implements Transport {
* @inheritDoc
*/
public recordLostEvent(type: Outcome): void {
if (!this.options.sendClientReport) {
return;
}

logger.log(`Adding ${type} outcome`);
this._outcomes[type] = (this._outcomes[type] ?? 0) + 1;
}
Expand All @@ -75,6 +79,10 @@ export abstract class BaseTransport implements Transport {
* Send outcomes as an envelope
*/
protected _flushOutcomes(): void {
if (!this.options.sendClientReport) {
return;
}

if (!navigator || typeof navigator.sendBeacon !== 'function') {
logger.warn('Beacon API not available, skipping sending outcomes.');
return;
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/options.ts
Expand Up @@ -132,6 +132,11 @@ export interface Options {
*/
autoSessionTracking?: boolean;

/**
* Automatically send SDK Client Report
*/
sendClientReports?: boolean;

/**
* Initial data to populate scope.
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/transport.ts
Expand Up @@ -64,6 +64,8 @@ export interface TransportOptions {
fetchParameters?: { [key: string]: string };
/** The envelope tunnel to use. */
tunnel?: string;
/** Automatically send SDK Client Report */
sendClientReport?: boolean;
/**
* Set of metadata about the SDK that can be internally used to enhance envelopes and events,
* and provide additional data about every request.
Expand Down

0 comments on commit 498fa19

Please sign in to comment.