Skip to content

Commit 1f5edf6

Browse files
authored
feat(core)!: Stop accepting event as argument for recordDroppedEvent (#14999)
The event was no longer used for some time, instead you can (optionally) pass a count of dropped events as third argument. This has been around since v7, so we can finally clean this up here, which should also save some bytes. This was not really deprecated before, but is also more an intimate API so I do not expect this to affect users too much. Also, deprecating arguments like this does not really work well with eslint anyhow, so even if we would deprecate it it is unlikely users would find out anyhow.
1 parent 463e8da commit 1f5edf6

File tree

6 files changed

+21
-62
lines changed

6 files changed

+21
-62
lines changed

docs/migration/v8-to-v9.md

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ Sentry.init({
199199
The following changes are unlikely to affect users of the SDK. They are listed here only for completion sake, and to alert users that may be relying on internal behavior.
200200

201201
- `client._prepareEvent()` now requires a currentScope & isolationScope to be passed as last arugments
202+
- `client.recordDroppedEvent()` no longer accepts an `event` as third argument. The event was no longer used for some time, instead you can (optionally) pass a count of dropped events as third argument.
202203

203204
### `@sentry/nestjs`
204205

packages/core/src/client.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,8 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
430430
/**
431431
* Record on the client that an event got dropped (ie, an event that will not be sent to Sentry).
432432
*/
433-
public recordDroppedEvent(reason: EventDropReason, category: DataCategory, eventOrCount?: Event | number): void {
433+
public recordDroppedEvent(reason: EventDropReason, category: DataCategory, count: number = 1): void {
434434
if (this._options.sendClientReports) {
435-
// TODO v9: We do not need the `event` passed as third argument anymore, and can possibly remove this overload
436-
// If event is passed as third argument, we assume this is a count of 1
437-
const count = typeof eventOrCount === 'number' ? eventOrCount : 1;
438-
439435
// We want to track each category (error, transaction, session, replay_event) separately
440436
// but still keep the distinction between different type of outcomes.
441437
// We could use nested maps, but it's much easier to read and type this way.
@@ -919,7 +915,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
919915
// Sampling for transaction happens somewhere else
920916
const parsedSampleRate = typeof sampleRate === 'undefined' ? undefined : parseSampleRate(sampleRate);
921917
if (isError && typeof parsedSampleRate === 'number' && Math.random() > parsedSampleRate) {
922-
this.recordDroppedEvent('sample_rate', 'error', event);
918+
this.recordDroppedEvent('sample_rate', 'error');
923919
return rejectedSyncPromise(
924920
new SentryError(
925921
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
@@ -933,7 +929,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
933929
return this._prepareEvent(event, hint, currentScope, isolationScope)
934930
.then(prepared => {
935931
if (prepared === null) {
936-
this.recordDroppedEvent('event_processor', dataCategory, event);
932+
this.recordDroppedEvent('event_processor', dataCategory);
937933
throw new SentryError('An event processor returned `null`, will not send event.', 'log');
938934
}
939935

@@ -947,7 +943,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
947943
})
948944
.then(processedEvent => {
949945
if (processedEvent === null) {
950-
this.recordDroppedEvent('before_send', dataCategory, event);
946+
this.recordDroppedEvent('before_send', dataCategory);
951947
if (isTransaction) {
952948
const spans = event.spans || [];
953949
// the transaction itself counts as one span, plus all the child spans that are added

packages/core/src/transports/base.ts

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1+
import { DEBUG_BUILD } from '../debug-build';
12
import type {
23
Envelope,
34
EnvelopeItem,
4-
EnvelopeItemType,
5-
Event,
65
EventDropReason,
7-
EventItem,
86
InternalBaseTransportOptions,
97
Transport,
108
TransportMakeRequestResponse,
119
TransportRequestExecutor,
1210
} from '../types-hoist';
13-
14-
import { DEBUG_BUILD } from '../debug-build';
1511
import {
1612
createEnvelope,
1713
envelopeItemTypeToDataCategory,
@@ -49,8 +45,7 @@ export function createTransport(
4945
forEachEnvelopeItem(envelope, (item, type) => {
5046
const dataCategory = envelopeItemTypeToDataCategory(type);
5147
if (isRateLimited(rateLimits, dataCategory)) {
52-
const event: Event | undefined = getEventForEnvelopeItem(item, type);
53-
options.recordDroppedEvent('ratelimit_backoff', dataCategory, event);
48+
options.recordDroppedEvent('ratelimit_backoff', dataCategory);
5449
} else {
5550
filteredEnvelopeItems.push(item);
5651
}
@@ -66,8 +61,7 @@ export function createTransport(
6661
// Creates client report for each item in an envelope
6762
const recordEnvelopeLoss = (reason: EventDropReason): void => {
6863
forEachEnvelopeItem(filteredEnvelope, (item, type) => {
69-
const event: Event | undefined = getEventForEnvelopeItem(item, type);
70-
options.recordDroppedEvent(reason, envelopeItemTypeToDataCategory(type), event);
64+
options.recordDroppedEvent(reason, envelopeItemTypeToDataCategory(type));
7165
});
7266
};
7367

@@ -107,11 +101,3 @@ export function createTransport(
107101
flush,
108102
};
109103
}
110-
111-
function getEventForEnvelopeItem(item: Envelope[1][number], type: EnvelopeItemType): Event | undefined {
112-
if (type !== 'event' && type !== 'transaction') {
113-
return undefined;
114-
}
115-
116-
return Array.isArray(item) ? (item as EventItem)[1] : undefined;
117-
}

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

+5-17
Original file line numberDiff line numberDiff line change
@@ -1517,9 +1517,7 @@ describe('Client', () => {
15171517
client.captureEvent({ message: 'hello' }, {});
15181518

15191519
expect(beforeSend).toHaveBeenCalled();
1520-
expect(recordLostEventSpy).toHaveBeenCalledWith('before_send', 'error', {
1521-
message: 'hello',
1522-
});
1520+
expect(recordLostEventSpy).toHaveBeenCalledWith('before_send', 'error');
15231521
});
15241522

15251523
test('`beforeSendTransaction` records dropped events', () => {
@@ -1539,10 +1537,7 @@ describe('Client', () => {
15391537
client.captureEvent({ transaction: '/dogs/are/great', type: 'transaction' });
15401538

15411539
expect(beforeSendTransaction).toHaveBeenCalled();
1542-
expect(recordLostEventSpy).toHaveBeenCalledWith('before_send', 'transaction', {
1543-
transaction: '/dogs/are/great',
1544-
type: 'transaction',
1545-
});
1540+
expect(recordLostEventSpy).toHaveBeenCalledWith('before_send', 'transaction');
15461541
});
15471542

15481543
test('event processor drops error event when it returns `null`', () => {
@@ -1594,9 +1589,7 @@ describe('Client', () => {
15941589

15951590
client.captureEvent({ message: 'hello' }, {}, scope);
15961591

1597-
expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'error', {
1598-
message: 'hello',
1599-
});
1592+
expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'error');
16001593
});
16011594

16021595
test('event processor records dropped transaction events', () => {
@@ -1612,10 +1605,7 @@ describe('Client', () => {
16121605

16131606
client.captureEvent({ transaction: '/dogs/are/great', type: 'transaction' }, {}, scope);
16141607

1615-
expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'transaction', {
1616-
transaction: '/dogs/are/great',
1617-
type: 'transaction',
1618-
});
1608+
expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'transaction');
16191609
});
16201610

16211611
test('mutating transaction name with event processors sets transaction-name-change metadata', () => {
@@ -1704,9 +1694,7 @@ describe('Client', () => {
17041694
const recordLostEventSpy = jest.spyOn(client, 'recordDroppedEvent');
17051695

17061696
client.captureEvent({ message: 'hello' }, {});
1707-
expect(recordLostEventSpy).toHaveBeenCalledWith('sample_rate', 'error', {
1708-
message: 'hello',
1709-
});
1697+
expect(recordLostEventSpy).toHaveBeenCalledWith('sample_rate', 'error');
17101698
});
17111699

17121700
test('captures logger message', () => {

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

+7-19
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ describe('createTransport', () => {
135135

136136
await transport.send(ERROR_ENVELOPE);
137137
expect(requestExecutor).not.toHaveBeenCalled();
138-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error', {
139-
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2',
140-
});
138+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error');
141139
requestExecutor.mockClear();
142140
recordDroppedEventCallback.mockClear();
143141

@@ -179,9 +177,7 @@ describe('createTransport', () => {
179177

180178
await transport.send(ERROR_ENVELOPE); // Error envelope should not be sent because of pending rate limit
181179
expect(requestExecutor).not.toHaveBeenCalled();
182-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error', {
183-
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2',
184-
});
180+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error');
185181
requestExecutor.mockClear();
186182
recordDroppedEventCallback.mockClear();
187183

@@ -223,23 +219,19 @@ describe('createTransport', () => {
223219

224220
await transport.send(TRANSACTION_ENVELOPE); // Transaction envelope should not be sent because of pending rate limit
225221
expect(requestExecutor).not.toHaveBeenCalled();
226-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'transaction', {
227-
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2',
228-
});
222+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'transaction');
229223
requestExecutor.mockClear();
230224
recordDroppedEventCallback.mockClear();
231225

232226
await transport.send(ERROR_ENVELOPE); // Error envelope should not be sent because of pending rate limit
233227
expect(requestExecutor).not.toHaveBeenCalled();
234-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error', {
235-
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2',
236-
});
228+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error');
237229
requestExecutor.mockClear();
238230
recordDroppedEventCallback.mockClear();
239231

240232
await transport.send(ATTACHMENT_ENVELOPE); // Attachment envelope should not be sent because of pending rate limit
241233
expect(requestExecutor).not.toHaveBeenCalled();
242-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'attachment', undefined);
234+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'attachment');
243235
requestExecutor.mockClear();
244236
recordDroppedEventCallback.mockClear();
245237

@@ -287,17 +279,13 @@ describe('createTransport', () => {
287279

288280
await transport.send(TRANSACTION_ENVELOPE); // Transaction envelope should not be sent because of pending rate limit
289281
expect(requestExecutor).not.toHaveBeenCalled();
290-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'transaction', {
291-
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2',
292-
});
282+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'transaction');
293283
requestExecutor.mockClear();
294284
recordDroppedEventCallback.mockClear();
295285

296286
await transport.send(ERROR_ENVELOPE); // Error envelope should not be sent because of pending rate limit
297287
expect(requestExecutor).not.toHaveBeenCalled();
298-
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error', {
299-
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2',
300-
});
288+
expect(recordDroppedEventCallback).toHaveBeenCalledWith('ratelimit_backoff', 'error');
301289
requestExecutor.mockClear();
302290
recordDroppedEventCallback.mockClear();
303291

packages/replay-internal/src/util/sendReplayRequest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function sendReplayRequest({
5353

5454
if (!replayEvent) {
5555
// Taken from baseclient's `_processEvent` method, where this is handled for errors/transactions
56-
client.recordDroppedEvent('event_processor', 'replay', baseEvent);
56+
client.recordDroppedEvent('event_processor', 'replay');
5757
DEBUG_BUILD && logger.info('An event processor returned `null`, will not send event.');
5858
return resolvedSyncPromise({});
5959
}

0 commit comments

Comments
 (0)