@@ -215,23 +215,26 @@ def prepare_host(host):
215
215
return host
216
216
217
217
218
- def report_json (region : Union [None , str ], msgs : List [dict ]) -> int :
218
+ def report_json (region : Union [None , str ], msgs : List [dict ], should_retry : bool = True ) -> int :
219
219
"""
220
220
This function sends the information back to the edge.
221
221
222
222
:param region: The region to use as default if not configured otherwise.
223
223
:param msgs: the message to send.
224
+ :param should_retry: False to disable the default retry on unsuccessful sending
224
225
:return: The duration of reporting (in milliseconds),
225
226
or 0 if we didn't send (due to configuration or fail).
226
227
"""
227
228
global edge_connection
228
229
get_logger ().info (f"reporting the messages: { msgs [:10 ]} " )
229
- host = prepare_host (Configuration .host or EDGE_HOST .format (region = region ))
230
- duration = 0
231
- if not edge_connection or edge_connection .host != host :
232
- edge_connection = establish_connection (host )
233
- if not edge_connection :
234
- return duration
230
+ host = None
231
+ with lumigo_safe_execute ("report json: establish connection" ):
232
+ host = prepare_host (Configuration .host or EDGE_HOST .format (region = region ))
233
+ duration = 0
234
+ if not edge_connection or edge_connection .host != host :
235
+ edge_connection = establish_connection (host )
236
+ if not edge_connection :
237
+ return duration
235
238
if Configuration .should_report :
236
239
try :
237
240
prune_trace : bool = not os .environ .get ("LUMIGO_PRUNE_TRACE_OFF" , "" ).lower () == "true"
@@ -245,10 +248,12 @@ def report_json(region: Union[None, str], msgs: List[dict]) -> int:
245
248
duration = int ((time .time () - start_time ) * 1000 )
246
249
get_logger ().info (f"successful reporting, code: { getattr (response , 'code' , 'unknown' )} " )
247
250
except Exception as e :
248
- get_logger ().exception (
249
- f"Could not report json to { host } . Retrying to establish connection." , exc_info = e
250
- )
251
- edge_connection = establish_connection (host )
251
+ if should_retry :
252
+ get_logger ().exception (f"Could not report to { host } . Retrying." , exc_info = e )
253
+ edge_connection = establish_connection (host )
254
+ report_json (region , msgs , should_retry = False )
255
+ else :
256
+ get_logger ().exception ("Could not report: A span was lost." , exc_info = e )
252
257
return duration
253
258
254
259
0 commit comments