Skip to content

Commit 8f40330

Browse files
committed
feat(v8/core): Add client outcomes for breadcrumbs buffer
1 parent d5f80af commit 8f40330

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

packages/core/src/scope.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,11 @@ class ScopeClass implements ScopeInterface {
443443
...breadcrumb,
444444
};
445445

446-
const breadcrumbs = this._breadcrumbs;
447-
breadcrumbs.push(mergedBreadcrumb);
448-
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
446+
this._breadcrumbs.push(mergedBreadcrumb);
447+
if (this._breadcrumbs.length > maxCrumbs) {
448+
this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
449+
this._client?.recordDroppedEvent('buffer_overflow', 'log_item');
450+
}
449451

450452
this._notifyScopeListeners();
451453

packages/core/src/types-hoist/clientreport.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export type EventDropReason =
88
| 'ratelimit_backoff'
99
| 'sample_rate'
1010
| 'send_error'
11-
| 'internal_sdk_error';
11+
| 'internal_sdk_error'
12+
| 'buffer_overflow';
1213

1314
export type Outcome = {
1415
reason: EventDropReason;

packages/core/src/types-hoist/datacategory.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type DataCategory =
1414
| 'replay'
1515
// Events with `event_type` csp, hpkp, expectct, expectstaple
1616
| 'security'
17-
// Attachment bytes stored (unused for rate limiting
17+
// Attachment bytes stored (unused for rate limiting)
1818
| 'attachment'
1919
// Session update events
2020
| 'session'
@@ -30,5 +30,9 @@ export type DataCategory =
3030
| 'metric_bucket'
3131
// Span
3232
| 'span'
33+
// Log event
34+
| 'log_item'
35+
// Log bytes stored (unused for rate limiting)
36+
| 'log_byte'
3337
// Unknown data category
3438
| 'unknown';

packages/core/test/lib/baseclient.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ describe('BaseClient', () => {
201201
expect(isolationScopeBreadcrumbs).toEqual([{ message: 'hello3', timestamp: expect.any(Number) }]);
202202
});
203203

204+
test('it records `buffer_overflow` client discard reason when buffer overflows', () => {
205+
const options = getDefaultTestClientOptions({ maxBreadcrumbs: 1 });
206+
const client = new TestClient(options);
207+
const recordLostEventSpy = jest.spyOn(client, 'recordDroppedEvent');
208+
setCurrentClient(client);
209+
getIsolationScope().setClient(client);
210+
client.init();
211+
212+
addBreadcrumb({ message: 'hello1' });
213+
addBreadcrumb({ message: 'hello2' });
214+
addBreadcrumb({ message: 'hello3' });
215+
216+
expect(recordLostEventSpy).toHaveBeenCalledTimes(2);
217+
expect(recordLostEventSpy).toHaveBeenLastCalledWith('buffer_overflow', 'log_item');
218+
});
219+
204220
test('calls `beforeBreadcrumb` and adds the breadcrumb without any changes', () => {
205221
const beforeBreadcrumb = jest.fn(breadcrumb => breadcrumb);
206222
const options = getDefaultTestClientOptions({ beforeBreadcrumb });

0 commit comments

Comments
 (0)