@@ -150,12 +150,14 @@ def _update_rate_limits(self, response):
150
150
# no matter of the status code to update our internal rate limits.
151
151
header = response .headers .get ("x-sentry-rate-limits" )
152
152
if header :
153
+ logger .warning ("Rate-limited via x-sentry-rate-limits" )
153
154
self ._disabled_until .update (_parse_rate_limits (header ))
154
155
155
156
# old sentries only communicate global rate limit hits via the
156
157
# retry-after header on 429. This header can also be emitted on new
157
158
# sentries if a proxy in front wants to globally slow things down.
158
159
elif response .status == 429 :
160
+ logger .warning ("Rate-limited via 429" )
159
161
self ._disabled_until [None ] = datetime .utcnow () + timedelta (
160
162
seconds = self ._retry .get_retry_after (response ) or 60
161
163
)
@@ -173,19 +175,24 @@ def _send_request(
173
175
"X-Sentry-Auth" : str (self ._auth .to_header ()),
174
176
}
175
177
)
176
- response = self ._pool .request (
177
- "POST" ,
178
- str (self ._auth .get_api_url (endpoint_type )),
179
- body = body ,
180
- headers = headers ,
181
- )
178
+ try :
179
+ response = self ._pool .request (
180
+ "POST" ,
181
+ str (self ._auth .get_api_url (endpoint_type )),
182
+ body = body ,
183
+ headers = headers ,
184
+ )
185
+ except Exception :
186
+ self .on_dropped_event ("network" )
187
+ raise
182
188
183
189
try :
184
190
self ._update_rate_limits (response )
185
191
186
192
if response .status == 429 :
187
193
# if we hit a 429. Something was rate limited but we already
188
194
# acted on this in `self._update_rate_limits`.
195
+ self .on_dropped_event ("status_429" )
189
196
pass
190
197
191
198
elif response .status >= 300 or response .status < 200 :
@@ -194,9 +201,14 @@ def _send_request(
194
201
response .status ,
195
202
response .data ,
196
203
)
204
+ self .on_dropped_event ("status_{}" .format (response .status ))
197
205
finally :
198
206
response .close ()
199
207
208
+ def on_dropped_event (self , reason ):
209
+ # type: (str) -> None
210
+ pass
211
+
200
212
def _check_disabled (self , category ):
201
213
# type: (str) -> bool
202
214
def _disabled (bucket ):
@@ -212,6 +224,7 @@ def _send_event(
212
224
# type: (...) -> None
213
225
214
226
if self ._check_disabled ("error" ):
227
+ self .on_dropped_event ("self_rate_limits" )
215
228
return None
216
229
217
230
body = io .BytesIO ()
@@ -325,7 +338,8 @@ def send_event_wrapper():
325
338
with capture_internal_exceptions ():
326
339
self ._send_event (event )
327
340
328
- self ._worker .submit (send_event_wrapper )
341
+ if not self ._worker .submit (send_event_wrapper ):
342
+ self .on_dropped_event ("full_queue" )
329
343
330
344
def capture_envelope (
331
345
self , envelope # type: Envelope
@@ -339,7 +353,8 @@ def send_envelope_wrapper():
339
353
with capture_internal_exceptions ():
340
354
self ._send_envelope (envelope )
341
355
342
- self ._worker .submit (send_envelope_wrapper )
356
+ if not self ._worker .submit (send_envelope_wrapper ):
357
+ self .on_dropped_event ("full_queue" )
343
358
344
359
def flush (
345
360
self ,
0 commit comments