1
- import { EventEnvelope , EventItem , TransportMakeRequestResponse } from '@sentry/types' ;
1
+ import { AttachmentItem , EventEnvelope , EventItem , TransportMakeRequestResponse } from '@sentry/types' ;
2
2
import { createEnvelope , PromiseBuffer , resolvedSyncPromise , serializeEnvelope } from '@sentry/utils' ;
3
3
import { TextEncoder } from 'util' ;
4
4
@@ -13,6 +13,22 @@ const TRANSACTION_ENVELOPE = createEnvelope<EventEnvelope>(
13
13
[ [ { type : 'transaction' } , { event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' } ] as EventItem ] ,
14
14
) ;
15
15
16
+ const ATTACHMENT_ENVELOPE = createEnvelope < EventEnvelope > (
17
+ { event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' , sent_at : '123' } ,
18
+ [
19
+ [
20
+ {
21
+ type : 'attachment' ,
22
+ length : 20 ,
23
+ filename : 'test-file.txt' ,
24
+ content_type : 'text/plain' ,
25
+ attachment_type : 'text' ,
26
+ } ,
27
+ 'attachment content' ,
28
+ ] as AttachmentItem ,
29
+ ] ,
30
+ ) ;
31
+
16
32
const transportOptions = {
17
33
recordDroppedEvent : ( ) => undefined , // noop
18
34
textEncoder : new TextEncoder ( ) ,
@@ -122,7 +138,9 @@ describe('createTransport', () => {
122
138
123
139
await transport . send ( ERROR_ENVELOPE ) ;
124
140
expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
125
- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
141
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
142
+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
143
+ } ) ;
126
144
requestExecutor . mockClear ( ) ;
127
145
recordDroppedEventCallback . mockClear ( ) ;
128
146
@@ -164,7 +182,9 @@ describe('createTransport', () => {
164
182
165
183
await transport . send ( ERROR_ENVELOPE ) ; // Error envelope should not be sent because of pending rate limit
166
184
expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
167
- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
185
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
186
+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
187
+ } ) ;
168
188
requestExecutor . mockClear ( ) ;
169
189
recordDroppedEventCallback . mockClear ( ) ;
170
190
@@ -186,7 +206,7 @@ describe('createTransport', () => {
186
206
const { retryAfterSeconds, beforeLimit, withinLimit, afterLimit } = setRateLimitTimes ( ) ;
187
207
const [ transport , setTransportResponse , requestExecutor , recordDroppedEventCallback ] = createTestTransport ( {
188
208
headers : {
189
- 'x-sentry-rate-limits' : `${ retryAfterSeconds } :error;transaction:scope` ,
209
+ 'x-sentry-rate-limits' : `${ retryAfterSeconds } :error;transaction;attachment :scope` ,
190
210
'retry-after' : null ,
191
211
} ,
192
212
} ) ;
@@ -206,13 +226,23 @@ describe('createTransport', () => {
206
226
207
227
await transport . send ( TRANSACTION_ENVELOPE ) ; // Transaction envelope should not be sent because of pending rate limit
208
228
expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
209
- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' ) ;
229
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' , {
230
+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
231
+ } ) ;
210
232
requestExecutor . mockClear ( ) ;
211
233
recordDroppedEventCallback . mockClear ( ) ;
212
234
213
235
await transport . send ( ERROR_ENVELOPE ) ; // Error envelope should not be sent because of pending rate limit
214
236
expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
215
- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
237
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
238
+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
239
+ } ) ;
240
+ requestExecutor . mockClear ( ) ;
241
+ recordDroppedEventCallback . mockClear ( ) ;
242
+
243
+ await transport . send ( ATTACHMENT_ENVELOPE ) ; // Attachment envelope should not be sent because of pending rate limit
244
+ expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
245
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'attachment' , undefined ) ;
216
246
requestExecutor . mockClear ( ) ;
217
247
recordDroppedEventCallback . mockClear ( ) ;
218
248
@@ -228,6 +258,12 @@ describe('createTransport', () => {
228
258
await transport . send ( ERROR_ENVELOPE ) ;
229
259
expect ( requestExecutor ) . toHaveBeenCalledTimes ( 1 ) ;
230
260
expect ( recordDroppedEventCallback ) . not . toHaveBeenCalled ( ) ;
261
+ requestExecutor . mockClear ( ) ;
262
+ recordDroppedEventCallback . mockClear ( ) ;
263
+
264
+ await transport . send ( ATTACHMENT_ENVELOPE ) ;
265
+ expect ( requestExecutor ) . toHaveBeenCalledTimes ( 1 ) ;
266
+ expect ( recordDroppedEventCallback ) . not . toHaveBeenCalled ( ) ;
231
267
} ) ;
232
268
233
269
it ( 'back-off using X-Sentry-Rate-Limits with missing categories should lock them all' , async ( ) => {
@@ -254,13 +290,17 @@ describe('createTransport', () => {
254
290
255
291
await transport . send ( TRANSACTION_ENVELOPE ) ; // Transaction envelope should not be sent because of pending rate limit
256
292
expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
257
- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' ) ;
293
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' , {
294
+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
295
+ } ) ;
258
296
requestExecutor . mockClear ( ) ;
259
297
recordDroppedEventCallback . mockClear ( ) ;
260
298
261
299
await transport . send ( ERROR_ENVELOPE ) ; // Error envelope should not be sent because of pending rate limit
262
300
expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
263
- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
301
+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
302
+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
303
+ } ) ;
264
304
requestExecutor . mockClear ( ) ;
265
305
recordDroppedEventCallback . mockClear ( ) ;
266
306
0 commit comments