@@ -2,6 +2,7 @@ use httpdate::parse_http_date;
22use  std:: time:: { Duration ,  SystemTime } ; 
33
44use  crate :: protocol:: EnvelopeItem ; 
5+ use  crate :: protocol:: ItemContainer ; 
56use  crate :: Envelope ; 
67
78/// A Utility that helps with rate limiting sentry requests. 
@@ -12,6 +13,7 @@ pub struct RateLimiter {
1213    session :  Option < SystemTime > , 
1314    transaction :  Option < SystemTime > , 
1415    attachment :  Option < SystemTime > , 
16+     log_item :  Option < SystemTime > , 
1517} 
1618
1719impl  RateLimiter  { 
@@ -56,6 +58,7 @@ impl RateLimiter {
5658                    "session"  => self . session  = new_time, 
5759                    "transaction"  => self . transaction  = new_time, 
5860                    "attachment"  => self . attachment  = new_time, 
61+                     "log_item"  => self . log_item  = new_time, 
5962                    _ => { } 
6063                } 
6164            } 
@@ -89,6 +92,7 @@ impl RateLimiter {
8992            RateLimitingCategory :: Session  => self . session , 
9093            RateLimitingCategory :: Transaction  => self . transaction , 
9194            RateLimitingCategory :: Attachment  => self . attachment , 
95+             RateLimitingCategory :: LogItem  => self . log_item , 
9296        } ?; 
9397        time_left. duration_since ( SystemTime :: now ( ) ) . ok ( ) 
9498    } 
@@ -112,6 +116,9 @@ impl RateLimiter {
112116                } 
113117                EnvelopeItem :: Transaction ( _)  => RateLimitingCategory :: Transaction , 
114118                EnvelopeItem :: Attachment ( _)  => RateLimitingCategory :: Attachment , 
119+                 EnvelopeItem :: ItemContainer ( ItemContainer :: Logs ( _) )  => { 
120+                     RateLimitingCategory :: LogItem 
121+                 } 
115122                _ => RateLimitingCategory :: Any , 
116123            } ) 
117124        } ) 
@@ -131,6 +138,8 @@ pub enum RateLimitingCategory {
131138Transaction , 
132139    /// Rate Limit pertaining to Attachments. 
133140Attachment , 
141+     /// Rate Limit pertaining to Log Items. 
142+ LogItem , 
134143} 
135144
136145#[ cfg( test) ]  
@@ -145,6 +154,7 @@ mod tests {
145154        assert ! ( rl. is_disabled( RateLimitingCategory :: Error ) . unwrap( )  <= Duration :: from_secs( 120 ) ) ; 
146155        assert ! ( rl. is_disabled( RateLimitingCategory :: Session ) . unwrap( )  <= Duration :: from_secs( 60 ) ) ; 
147156        assert ! ( rl. is_disabled( RateLimitingCategory :: Transaction ) . is_none( ) ) ; 
157+         assert ! ( rl. is_disabled( RateLimitingCategory :: LogItem ) . is_none( ) ) ; 
148158        assert ! ( rl. is_disabled( RateLimitingCategory :: Any ) . is_none( ) ) ; 
149159
150160        rl. update_from_sentry_header ( 
@@ -161,6 +171,23 @@ mod tests {
161171        assert ! ( rl. is_disabled( RateLimitingCategory :: Any ) . unwrap( )  <= Duration :: from_secs( 30 ) ) ; 
162172    } 
163173
174+     #[ test]  
175+     fn  test_sentry_header_no_categories ( )  { 
176+         let  mut  rl = RateLimiter :: new ( ) ; 
177+         rl. update_from_sentry_header ( "120::bar" ) ; 
178+ 
179+         assert ! ( rl. is_disabled( RateLimitingCategory :: Error ) . unwrap( )  <= Duration :: from_secs( 120 ) ) ; 
180+         assert ! ( rl. is_disabled( RateLimitingCategory :: Session ) . unwrap( )  <= Duration :: from_secs( 120 ) ) ; 
181+         assert ! ( 
182+             rl. is_disabled( RateLimitingCategory :: Transaction ) . unwrap( )  <= Duration :: from_secs( 120 ) 
183+         ) ; 
184+         assert ! ( rl. is_disabled( RateLimitingCategory :: LogItem ) . unwrap( )  <= Duration :: from_secs( 120 ) ) ; 
185+         assert ! ( 
186+             rl. is_disabled( RateLimitingCategory :: Attachment ) . unwrap( )  <= Duration :: from_secs( 120 ) 
187+         ) ; 
188+         assert ! ( rl. is_disabled( RateLimitingCategory :: Any ) . unwrap( )  <= Duration :: from_secs( 120 ) ) ; 
189+     } 
190+ 
164191    #[ test]  
165192    fn  test_retry_after ( )  { 
166193        let  mut  rl = RateLimiter :: new ( ) ; 
0 commit comments