Skip to content

Commit 0b45ed5

Browse files
committed
Code review updates
1 parent 25b0e5f commit 0b45ed5

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

packages/browser/src/transports/base.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,17 @@ export abstract class BaseTransport implements Transport {
6868
/**
6969
* @inheritDoc
7070
*/
71-
public recordLostEvent(type: Outcome, category: SentryRequestType): void {
71+
public recordLostEvent(reason: Outcome, category: SentryRequestType): void {
7272
if (!this.options.sendClientReport) {
7373
return;
7474
}
75-
const key = `${type}:${CATEGORY_MAPPING[category]}`;
76-
logger.log(`Adding ${key} outcome`);
75+
// We want to track each category (event, transaction, session) separately
76+
// but still keep the distinction between different type of outcomes.
77+
// We could use nested maps, but it's much easier to read and type this way.
78+
// A correct type for map-based implementation if we want to go that route
79+
// would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>`
80+
const key = `${CATEGORY_MAPPING[category]}:${reason}}`;
81+
logger.log(`Adding outcome: ${key}`);
7782
this._outcomes[key] = (this._outcomes[key] ?? 0) + 1;
7883
}
7984

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

9398
const outcomes = this._outcomes;
99+
this._outcomes = {};
94100

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

120126
navigator.sendBeacon(url, envelope);
121-
122-
this._outcomes = {};
123127
}
124128

125129
/**

packages/core/src/baseclient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
187187
* @inheritDoc
188188
*/
189189
public getTransport(): Transport {
190-
return this.getTransport();
190+
return this._getBackend().getTransport();
191191
}
192192

193193
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('BaseClient', () => {
9090

9191
describe('getTransport()', () => {
9292
test('returns the transport from backend', () => {
93-
expect.assertions(1);
93+
expect.assertions(2);
9494
const options = { dsn: PUBLIC_DSN, transport: FakeTransport };
9595
const client = new TestClient(options);
9696
expect(client.getTransport()).toBeInstanceOf(FakeTransport);

packages/types/src/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ export interface Options {
133133
autoSessionTracking?: boolean;
134134

135135
/**
136-
* Automatically send SDK Client Report
136+
* Send SDK Client Reports.
137+
* By default, Client Reports are enabled.
137138
*/
138139
sendClientReports?: boolean;
139140

0 commit comments

Comments
 (0)