1- import { EventEnvelope , EventItem , TransportMakeRequestResponse } from '@sentry/types' ;
1+ import { AttachmentItem , EventEnvelope , EventItem , TransportMakeRequestResponse } from '@sentry/types' ;
22import { createEnvelope , PromiseBuffer , resolvedSyncPromise , serializeEnvelope } from '@sentry/utils' ;
33import { TextEncoder } from 'util' ;
44
@@ -13,6 +13,22 @@ const TRANSACTION_ENVELOPE = createEnvelope<EventEnvelope>(
1313 [ [ { type : 'transaction' } , { event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' } ] as EventItem ] ,
1414) ;
1515
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+
1632const transportOptions = {
1733 recordDroppedEvent : ( ) => undefined , // noop
1834 textEncoder : new TextEncoder ( ) ,
@@ -122,7 +138,9 @@ describe('createTransport', () => {
122138
123139 await transport . send ( ERROR_ENVELOPE ) ;
124140 expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
125- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
141+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
142+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
143+ } ) ;
126144 requestExecutor . mockClear ( ) ;
127145 recordDroppedEventCallback . mockClear ( ) ;
128146
@@ -164,7 +182,9 @@ describe('createTransport', () => {
164182
165183 await transport . send ( ERROR_ENVELOPE ) ; // Error envelope should not be sent because of pending rate limit
166184 expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
167- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
185+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
186+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
187+ } ) ;
168188 requestExecutor . mockClear ( ) ;
169189 recordDroppedEventCallback . mockClear ( ) ;
170190
@@ -186,7 +206,7 @@ describe('createTransport', () => {
186206 const { retryAfterSeconds, beforeLimit, withinLimit, afterLimit } = setRateLimitTimes ( ) ;
187207 const [ transport , setTransportResponse , requestExecutor , recordDroppedEventCallback ] = createTestTransport ( {
188208 headers : {
189- 'x-sentry-rate-limits' : `${ retryAfterSeconds } :error;transaction:scope` ,
209+ 'x-sentry-rate-limits' : `${ retryAfterSeconds } :error;transaction;attachment :scope` ,
190210 'retry-after' : null ,
191211 } ,
192212 } ) ;
@@ -206,13 +226,23 @@ describe('createTransport', () => {
206226
207227 await transport . send ( TRANSACTION_ENVELOPE ) ; // Transaction envelope should not be sent because of pending rate limit
208228 expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
209- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' ) ;
229+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' , {
230+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
231+ } ) ;
210232 requestExecutor . mockClear ( ) ;
211233 recordDroppedEventCallback . mockClear ( ) ;
212234
213235 await transport . send ( ERROR_ENVELOPE ) ; // Error envelope should not be sent because of pending rate limit
214236 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 ) ;
216246 requestExecutor . mockClear ( ) ;
217247 recordDroppedEventCallback . mockClear ( ) ;
218248
@@ -228,6 +258,12 @@ describe('createTransport', () => {
228258 await transport . send ( ERROR_ENVELOPE ) ;
229259 expect ( requestExecutor ) . toHaveBeenCalledTimes ( 1 ) ;
230260 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 ( ) ;
231267 } ) ;
232268
233269 it ( 'back-off using X-Sentry-Rate-Limits with missing categories should lock them all' , async ( ) => {
@@ -254,13 +290,17 @@ describe('createTransport', () => {
254290
255291 await transport . send ( TRANSACTION_ENVELOPE ) ; // Transaction envelope should not be sent because of pending rate limit
256292 expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
257- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' ) ;
293+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'transaction' , {
294+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
295+ } ) ;
258296 requestExecutor . mockClear ( ) ;
259297 recordDroppedEventCallback . mockClear ( ) ;
260298
261299 await transport . send ( ERROR_ENVELOPE ) ; // Error envelope should not be sent because of pending rate limit
262300 expect ( requestExecutor ) . not . toHaveBeenCalled ( ) ;
263- expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' ) ;
301+ expect ( recordDroppedEventCallback ) . toHaveBeenCalledWith ( 'ratelimit_backoff' , 'error' , {
302+ event_id : 'aa3ff046696b4bc6b609ce6d28fde9e2' ,
303+ } ) ;
264304 requestExecutor . mockClear ( ) ;
265305 recordDroppedEventCallback . mockClear ( ) ;
266306
0 commit comments