@@ -7,12 +7,14 @@ import type {
7
7
ReplayEvent ,
8
8
Transport ,
9
9
TransportMakeRequestResponse ,
10
+ ClientReport ,
10
11
} from '@sentry/types' ;
11
12
import {
12
13
createEnvelope ,
13
14
createEventEnvelopeHeaders ,
14
15
dsnFromString ,
15
16
getSdkMetadataForEnvelopeHeader ,
17
+ createClientReportEnvelope ,
16
18
} from '@sentry/utils' ;
17
19
import { TextEncoder } from 'util' ;
18
20
@@ -54,6 +56,25 @@ const RELAY_ENVELOPE = createEnvelope<ReplayEnvelope>(
54
56
] ,
55
57
) ;
56
58
59
+ const DEFAULT_DISCARDED_EVENTS : ClientReport [ 'discarded_events' ] = [
60
+ {
61
+ reason : 'before_send' ,
62
+ category : 'error' ,
63
+ quantity : 30 ,
64
+ } ,
65
+ {
66
+ reason : 'network_error' ,
67
+ category : 'transaction' ,
68
+ quantity : 23 ,
69
+ } ,
70
+ ] ;
71
+
72
+ const CLIENT_REPORT_ENVELOPE = createClientReportEnvelope (
73
+ DEFAULT_DISCARDED_EVENTS ,
74
+
75
+ 123456 ,
76
+ ) ;
77
+
57
78
const transportOptions = {
58
79
recordDroppedEvent : ( ) => undefined , // noop
59
80
textEncoder : new TextEncoder ( ) ,
@@ -288,6 +309,23 @@ describe('makeOfflineTransport', () => {
288
309
expect ( getCalls ( ) ) . toEqual ( [ ] ) ;
289
310
} ) ;
290
311
312
+ it ( 'should not store client report envelopes on send failure' , async ( ) => {
313
+ const { getCalls, store } = createTestStore ( ) ;
314
+ const { getSendCount, baseTransport } = createTestTransport ( new Error ( ) ) ;
315
+ const queuedCount = 0 ;
316
+ const transport = makeOfflineTransport ( baseTransport ) ( {
317
+ ...transportOptions ,
318
+ createStore : store ,
319
+ shouldStore : ( ) => true ,
320
+ } ) ;
321
+ const result = transport . send ( CLIENT_REPORT_ENVELOPE ) ;
322
+
323
+ await expect ( result ) . rejects . toBeInstanceOf ( Error ) ;
324
+ expect ( queuedCount ) . toEqual ( 0 ) ;
325
+ expect ( getSendCount ( ) ) . toEqual ( 0 ) ;
326
+ expect ( getCalls ( ) ) . toEqual ( [ ] ) ;
327
+ } ) ;
328
+
291
329
it (
292
330
'Follows the Retry-After header' ,
293
331
async ( ) => {
0 commit comments