Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,13 @@ class ScopeClass implements ScopeInterface {
...breadcrumb,
};

const breadcrumbs = this._breadcrumbs;
breadcrumbs.push(mergedBreadcrumb);
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
this._breadcrumbs.push(mergedBreadcrumb);
if (this._breadcrumbs.length > maxCrumbs) {
this._breadcrumbs = this._breadcrumbs.slice(-maxCrumbs);
if (this._client) {
this._client.recordDroppedEvent('buffer_overflow', 'log_item');
}
}

this._notifyScopeListeners();

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types-hoist/clientreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export type EventDropReason =
| 'ratelimit_backoff'
| 'sample_rate'
| 'send_error'
| 'internal_sdk_error';
| 'internal_sdk_error'
| 'buffer_overflow';

export type Outcome = {
reason: EventDropReason;
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/types-hoist/datacategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type DataCategory =
| 'replay'
// Events with `event_type` csp, hpkp, expectct, expectstaple
| 'security'
// Attachment bytes stored (unused for rate limiting
// Attachment bytes stored (unused for rate limiting)
| 'attachment'
// Session update events
| 'session'
Expand All @@ -30,5 +30,9 @@ export type DataCategory =
| 'metric_bucket'
// Span
| 'span'
// Log event
| 'log_item'
// Log bytes stored (unused for rate limiting)
| 'log_byte'
// Unknown data category
| 'unknown';
16 changes: 16 additions & 0 deletions packages/core/test/lib/baseclient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ describe('BaseClient', () => {
expect(isolationScopeBreadcrumbs).toEqual([{ message: 'hello3', timestamp: expect.any(Number) }]);
});

test('it records `buffer_overflow` client discard reason when buffer overflows', () => {
const options = getDefaultTestClientOptions({ maxBreadcrumbs: 1 });
const client = new TestClient(options);
const recordLostEventSpy = jest.spyOn(client, 'recordDroppedEvent');
setCurrentClient(client);
getIsolationScope().setClient(client);
client.init();

addBreadcrumb({ message: 'hello1' });
addBreadcrumb({ message: 'hello2' });
addBreadcrumb({ message: 'hello3' });

expect(recordLostEventSpy).toHaveBeenCalledTimes(2);
expect(recordLostEventSpy).toHaveBeenLastCalledWith('buffer_overflow', 'log_item');
});

test('calls `beforeBreadcrumb` and adds the breadcrumb without any changes', () => {
const beforeBreadcrumb = jest.fn(breadcrumb => breadcrumb);
const options = getDefaultTestClientOptions({ beforeBreadcrumb });
Expand Down
Loading