Skip to content

Commit 9622bba

Browse files
authored
feat(core): Add client outcomes for breadcrumbs buffer (#15082)
ref getsentry/team-sdks#116 This PR implements a new client discard reason for `buffer_overflow`. This will be used to track when the internal breadcrumbs buffer overflows for the new logs product that we are working on. This is documented in develop here: getsentry/sentry-docs#12395 Note: The reason we have `buffer_overflow` as a separate item to `queue_overflow` is that in the future when we send log items in envelopes we'll increment `queue_overflow` for the transport queue. We want to differentiate between the transport queue and the internal buffer explicitly.
1 parent d789766 commit 9622bba

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
@@ -479,9 +479,11 @@ export class Scope {
479479
...breadcrumb,
480480
};
481481

482-
const breadcrumbs = this._breadcrumbs;
483-
breadcrumbs.push(mergedBreadcrumb);
484-
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
482+
this._breadcrumbs.push(mergedBreadcrumb);
483+
if (this._breadcrumbs.length > maxCrumbs) {
484+
this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
485+
this._client?.recordDroppedEvent('buffer_overflow', 'log_item');
486+
}
485487

486488
this._notifyScopeListeners();
487489

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'
@@ -28,5 +28,9 @@ export type DataCategory =
2828
| 'feedback'
2929
// Span
3030
| 'span'
31+
// Log event
32+
| 'log_item'
33+
// Log bytes stored (unused for rate limiting)
34+
| 'log_byte'
3135
// Unknown data category
3236
| 'unknown';

packages/core/test/lib/client.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ describe('Client', () => {
164164
expect(isolationScopeBreadcrumbs).toEqual([{ message: 'hello3', timestamp: expect.any(Number) }]);
165165
});
166166

167+
test('it records `buffer_overflow` client discard reason when buffer overflows', () => {
168+
const options = getDefaultTestClientOptions({ maxBreadcrumbs: 1 });
169+
const client = new TestClient(options);
170+
const recordLostEventSpy = jest.spyOn(client, 'recordDroppedEvent');
171+
setCurrentClient(client);
172+
getIsolationScope().setClient(client);
173+
client.init();
174+
175+
addBreadcrumb({ message: 'hello1' });
176+
addBreadcrumb({ message: 'hello2' });
177+
addBreadcrumb({ message: 'hello3' });
178+
179+
expect(recordLostEventSpy).toHaveBeenCalledTimes(2);
180+
expect(recordLostEventSpy).toHaveBeenLastCalledWith('buffer_overflow', 'log_item');
181+
});
182+
167183
test('calls `beforeBreadcrumb` and adds the breadcrumb without any changes', () => {
168184
const beforeBreadcrumb = jest.fn(breadcrumb => breadcrumb);
169185
const options = getDefaultTestClientOptions({ beforeBreadcrumb });

0 commit comments

Comments
 (0)