@@ -94,9 +94,6 @@ def _transmit(self, envelopes):
9494 except requests .RequestException as ex :
9595 logger .warning (
9696 'Retrying due to transient client side error %s.' , ex )
97- if self ._check_stats_collection ():
98- with _requests_lock :
99- _requests_map ['retry' ] = _requests_map .get ('retry' , 0 ) + 1 # noqa: E501
10097 # client side error (retryable)
10198 exception = self .options .minimum_retry_interval
10299 except CredentialUnavailableError as ex :
@@ -108,9 +105,6 @@ def _transmit(self, envelopes):
108105 except Exception as ex :
109106 logger .warning (
110107 'Error when sending request %s. Dropping telemetry.' , ex )
111- if self ._check_stats_collection ():
112- with _requests_lock :
113- _requests_map ['exception' ] = _requests_map .get ('exception' , 0 ) + 1 # noqa: E501
114108 # Extraneous error (non-retryable)
115109 exception = - 1
116110 finally :
@@ -120,6 +114,13 @@ def _transmit(self, envelopes):
120114 duration = _requests_map .get ('duration' , 0 )
121115 _requests_map ['duration' ] = duration + (end_time - start_time ) # noqa: E501
122116 if exception is not None :
117+ if self ._check_stats_collection ():
118+ with _requests_lock :
119+ if exception >= 0 :
120+ _requests_map ['retry' ] = _requests_map .get ('retry' , 0 ) + 1 # noqa: E501
121+ else :
122+ _requests_map ['exception' ] = _requests_map .get ('exception' , 0 ) + 1 # noqa: E501
123+
123124 return exception
124125
125126 text = 'N/A'
@@ -139,10 +140,11 @@ def _transmit(self, envelopes):
139140 with _requests_lock :
140141 _requests_map ['success' ] = _requests_map .get ('success' , 0 ) + 1 # noqa: E501
141142 return 0
142- # Status code not 200 counts as failure
143+ # Status code not 200, 439 or 402 counts as failures
143144 if self ._check_stats_collection ():
144- with _requests_lock :
145- _requests_map ['failure' ] = _requests_map .get ('failure' , 0 ) + 1 # noqa: E501
145+ if response .status_code != 439 and response .status_code != 402 :
146+ with _requests_lock :
147+ _requests_map ['failure' ] = _requests_map .get ('failure' , 0 ) + 1 # noqa: E501
146148 if response .status_code == 206 : # Partial Content
147149 if data :
148150 try :
@@ -162,6 +164,9 @@ def _transmit(self, envelopes):
162164 envelopes [error ['index' ]],
163165 )
164166 if resend_envelopes :
167+ if self ._check_stats_collection ():
168+ with _requests_lock :
169+ _requests_map ['retry' ] = _requests_map .get ('retry' , 0 ) + 1 # noqa: E501
165170 self .storage .put (resend_envelopes )
166171 except Exception as ex :
167172 logger .error (
@@ -170,9 +175,6 @@ def _transmit(self, envelopes):
170175 text ,
171176 ex ,
172177 )
173- if self ._check_stats_collection ():
174- with _requests_lock :
175- _requests_map ['retry' ] = _requests_map .get ('retry' , 0 ) + 1 # noqa: E501
176178 return - response .status_code
177179 # cannot parse response body, fallback to retry
178180 if response .status_code in (
@@ -189,11 +191,7 @@ def _transmit(self, envelopes):
189191 # server side error (retryable)
190192 if self ._check_stats_collection ():
191193 with _requests_lock :
192- # 429 counts as throttle instead of retry
193- if response .status_code == 429 :
194- _requests_map ['throttle' ] = _requests_map .get ('throttle' , 0 ) + 1 # noqa: E501
195- else :
196- _requests_map ['retry' ] = _requests_map .get ('retry' , 0 ) + 1 # noqa: E501
194+ _requests_map ['retry' ] = _requests_map .get ('retry' , 0 ) + 1 # noqa: E501
197195 return self .options .minimum_retry_interval
198196 # Authentication error
199197 if response .status_code == 401 :
@@ -235,14 +233,25 @@ def _transmit(self, envelopes):
235233 logger .error (
236234 "Error parsing redirect information."
237235 )
238- logger .error (
239- "Error sending telemetry because of circular redirects."
240- " Please check the integrity of your connection string."
241- )
236+ else :
237+ logger .error (
238+ "Error sending telemetry because of circular redirects."
239+ " Please check the integrity of your connection string."
240+ )
241+ # If redirect but did not return, exception occured
242+ if self ._check_stats_collection ():
243+ with _requests_lock :
244+ _requests_map ['exception' ] = _requests_map .get ('exception' , 0 ) + 1 # noqa: E501
245+ # Other, server side error (non-retryable)
242246 logger .error (
243247 'Non-retryable server side error %s: %s.' ,
244248 response .status_code ,
245249 text ,
246250 )
247- # server side error (non-retryable)
251+ if self ._check_stats_collection ():
252+ if response .status_code == 402 or response .status_code == 439 :
253+ # 402: Monthly Quota Exceeded (new SDK)
254+ # 439: Monthly Quota Exceeded (old SDK) <- Currently OC SDK
255+ with _requests_lock :
256+ _requests_map ['throttle' ] = _requests_map .get ('throttle' , 0 ) + 1 # noqa: E501
248257 return - response .status_code
0 commit comments