@@ -215,23 +215,26 @@ def prepare_host(host):
215215 return host
216216
217217
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 :
219219 """
220220 This function sends the information back to the edge.
221221
222222 :param region: The region to use as default if not configured otherwise.
223223 :param msgs: the message to send.
224+ :param should_retry: False to disable the default retry on unsuccessful sending
224225 :return: The duration of reporting (in milliseconds),
225226 or 0 if we didn't send (due to configuration or fail).
226227 """
227228 global edge_connection
228229 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
235238 if Configuration .should_report :
236239 try :
237240 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:
245248 duration = int ((time .time () - start_time ) * 1000 )
246249 get_logger ().info (f"successful reporting, code: { getattr (response , 'code' , 'unknown' )} " )
247250 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 )
252257 return duration
253258
254259
0 commit comments