Skip to content

Commit 45108d9

Browse files
committed
fix: Exclude client reports from offline storage
1 parent 7f4c4ec commit 45108d9

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

packages/core/src/transports/offline.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
import type { Envelope, InternalBaseTransportOptions, Transport, TransportMakeRequestResponse } from '@sentry/types';
2-
import { forEachEnvelopeItem, logger, parseRetryAfterHeader } from '@sentry/utils';
2+
import { envelopeContainItemType, logger, parseRetryAfterHeader } from '@sentry/utils';
33

44
export const MIN_DELAY = 100; // 100 ms
55
export const START_DELAY = 5_000; // 5 seconds
66
const MAX_DELAY = 3.6e6; // 1 hour
77

8-
function isReplayEnvelope(envelope: Envelope): boolean {
9-
let isReplay = false;
10-
11-
forEachEnvelopeItem(envelope, (_, type) => {
12-
if (type === 'replay_event') {
13-
isReplay = true;
14-
}
15-
});
16-
17-
return isReplay;
18-
}
19-
208
function log(msg: string, error?: Error): void {
219
__DEBUG_BUILD__ && logger.info(`[Offline]: ${msg}`, error);
2210
}
@@ -74,7 +62,8 @@ export function makeOfflineTransport<TO>(
7462
// We don't queue Session Replay envelopes because they are:
7563
// - Ordered and Replay relies on the response status to know when they're successfully sent.
7664
// - Likely to fill the queue quickly and block other events from being sent.
77-
if (isReplayEnvelope(env)) {
65+
// We also want to drop client reports because they can be generated when we retry sending events while offline.
66+
if (envelopeContainItemType(env, 'replay_event', 'replay_recording', 'client_report')) {
7867
return false;
7968
}
8069

packages/utils/src/envelope.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ export function forEachEnvelopeItem<E extends Envelope>(
5353
});
5454
}
5555

56+
/**
57+
* Returns true if the envelope contains any of the given envelope item types
58+
*/
59+
export function envelopeContainItemType(envelope: Envelope, ...types: EnvelopeItemType[]): boolean {
60+
let isType = false;
61+
62+
forEachEnvelopeItem(envelope, (_, type) => {
63+
if (types.includes(type)) {
64+
isType = true;
65+
}
66+
});
67+
68+
return isType;
69+
}
70+
5671
/**
5772
* Encode a string to UTF8.
5873
*/

0 commit comments

Comments
 (0)