Skip to content

Commit

Permalink
Code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Sep 8, 2021
1 parent e5ce2b0 commit 7d924e7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
14 changes: 9 additions & 5 deletions packages/browser/src/transports/base.ts
Expand Up @@ -68,12 +68,17 @@ export abstract class BaseTransport implements Transport {
/**
* @inheritDoc
*/
public recordLostEvent(type: Outcome, category: SentryRequestType): void {
public recordLostEvent(reason: Outcome, category: SentryRequestType): void {
if (!this.options.sendClientReport) {
return;
}
const key = `${type}:${CATEGORY_MAPPING[category]}`;
logger.log(`Adding ${key} outcome`);
// We want to track each category (event, transaction, session) separately
// but still keep the distinction between different type of outcomes.
// We could use nested maps, but it's much easier to read and type this way.
// A correct type for map-based implementation if we want to go that route
// would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
const key = `${CATEGORY_MAPPING[category]}:${reason}}`;
logger.log(`Adding outcome: ${key}`);
this._outcomes[key] = (this._outcomes[key] ?? 0) + 1;
}

Expand All @@ -91,6 +96,7 @@ export abstract class BaseTransport implements Transport {
}

const outcomes = this._outcomes;
this._outcomes = {};

// Nothing to send
if (!Object.keys(outcomes).length) {
Expand Down Expand Up @@ -118,8 +124,6 @@ export abstract class BaseTransport implements Transport {
const envelope = `${itemHeaders}\n${item}`;

navigator.sendBeacon(url, envelope);

this._outcomes = {};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/baseclient.ts
Expand Up @@ -187,7 +187,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
* @inheritDoc
*/
public getTransport(): Transport {
return this.getTransport();
return this._getBackend().getTransport();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/lib/base.test.ts
Expand Up @@ -90,7 +90,7 @@ describe('BaseClient', () => {

describe('getTransport()', () => {
test('returns the transport from backend', () => {
expect.assertions(1);
expect.assertions(2);
const options = { dsn: PUBLIC_DSN, transport: FakeTransport };
const client = new TestClient(options);
expect(client.getTransport()).toBeInstanceOf(FakeTransport);
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/options.ts
Expand Up @@ -133,7 +133,8 @@ export interface Options {
autoSessionTracking?: boolean;

/**
* Automatically send SDK Client Report
* Send SDK Client Reports.
* By default, Client Reports are enabled.
*/
sendClientReports?: boolean;

Expand Down

0 comments on commit 7d924e7

Please sign in to comment.