@@ -243,6 +243,11 @@ def _request(
243
243
if span and existing_transaction :
244
244
span .set_data ("existing_transaction" , existing_transaction )
245
245
246
+ extra = {"url" : full_url }
247
+ # It shouldn't be possible for integration_type to be null.
248
+ if self .integration_type :
249
+ extra [self .integration_type ] = self .name
250
+
246
251
try :
247
252
with build_session () as session :
248
253
finalized_request = self .finalize_request (_prepared_request )
@@ -266,30 +271,27 @@ def _request(
266
271
return resp
267
272
resp .raise_for_status ()
268
273
except RestrictedIPAddress as e :
269
- self .track_response_data ("restricted_ip_address" , span , e )
274
+ self .track_response_data ("restricted_ip_address" , span , e , extra = extra )
270
275
self .record_error (e )
271
276
raise ApiHostError .from_exception (e ) from e
272
277
except ConnectionError as e :
273
- self .track_response_data ("connection_error" , span , e )
278
+ self .track_response_data ("connection_error" , span , e , extra = extra )
274
279
self .record_error (e )
275
280
raise ApiHostError .from_exception (e ) from e
276
281
except Timeout as e :
277
- self .track_response_data ("timeout" , span , e )
282
+ self .track_response_data ("timeout" , span , e , extra = extra )
278
283
self .record_error (e )
279
284
raise ApiTimeoutError .from_exception (e ) from e
280
285
except HTTPError as e :
281
286
error_resp = e .response
282
287
if error_resp is None :
283
- self .track_response_data ("unknown" , span , e )
288
+ self .track_response_data ("unknown" , span , e , extra = extra )
284
289
285
- # It shouldn't be possible for integration_type to be null.
286
- extra = {"url" : full_url }
287
- if self .integration_type :
288
- extra [self .integration_type ] = self .name
289
290
self .logger .exception ("request.error" , extra = extra )
290
291
self .record_error (e )
291
292
raise ApiError ("Internal Error" , url = full_url ) from e
292
- self .track_response_data (error_resp .status_code , span , e )
293
+
294
+ self .track_response_data (error_resp .status_code , span , e , extra = extra )
293
295
self .record_error (e )
294
296
raise ApiError .from_response (error_resp , url = full_url ) from e
295
297
@@ -301,19 +303,19 @@ def _request(
301
303
# which is a ChunkedEncodingError caused by a ProtocolError caused by a ConnectionResetError.
302
304
# Rather than worrying about what the other layers might be, we just stringify to detect this.
303
305
if "ConnectionResetError" in str (e ):
304
- self .track_response_data ("connection_reset_error" , span , e )
306
+ self .track_response_data ("connection_reset_error" , span , e , extra = extra )
305
307
self .record_error (e )
306
308
raise ApiConnectionResetError ("Connection reset by peer" , url = full_url ) from e
307
309
# The same thing can happen with an InvalidChunkLength exception, which is a subclass of HTTPError
308
310
if "InvalidChunkLength" in str (e ):
309
- self .track_response_data ("invalid_chunk_length" , span , e )
311
+ self .track_response_data ("invalid_chunk_length" , span , e , extra = extra )
310
312
self .record_error (e )
311
313
raise ApiError ("Connection broken: invalid chunk length" , url = full_url ) from e
312
314
313
315
# If it's not something we recognize, let the caller deal with it
314
316
raise e
315
317
316
- self .track_response_data (resp .status_code , span , None , resp )
318
+ self .track_response_data (resp .status_code , span , None , resp , extra = extra )
317
319
318
320
self .record_response (resp )
319
321
0 commit comments