@@ -22,22 +22,28 @@ def send_log_to_firehose(log_data: dict) -> None:
2222
2323
2424def generate_and_send_logs (
25- start_time , base_log_data : dict , additional_log_data : dict , is_error_log : bool = False
25+ start_time : float ,
26+ base_log_data : dict ,
27+ additional_log_data : dict ,
28+ use_ms_precision : bool = False ,
29+ is_error_log : bool = False
2630) -> None :
2731 """Generates log data which includes the base_log_data, additional_log_data, and time taken (calculated using the
2832 current time and given start_time) and sends them to Cloudwatch and Firehose."""
29- log_data = {** base_log_data , "time_taken" : f"{ round (time .time () - start_time , 5 )} s" , ** additional_log_data }
33+ seconds_elapsed = time .time () - start_time
34+ time_elapsed = f"{ round (seconds_elapsed * 1000 , 5 )} ms" if use_ms_precision else f"{ round (seconds_elapsed , 5 )} s"
35+
36+ log_data = {** base_log_data , "time_taken" : time_elapsed , ** additional_log_data }
3037 log_function = logger .error if is_error_log else logger .info
3138 log_function (json .dumps (log_data ))
3239 send_log_to_firehose (log_data )
3340
3441
35- def convert_messsage_to_ack_row_logging_decorator (func ):
42+ def convert_message_to_ack_row_logging_decorator (func ):
3643 """This decorator logs the information on the conversion of a single message to an ack data row"""
3744
3845 @wraps (func )
3946 def wrapper (message , created_at_formatted_string ):
40-
4147 base_log_data = {"function_name" : f"ack_processor_{ func .__name__ } " , "date_time" : str (datetime .now ())}
4248 start_time = time .time ()
4349
@@ -57,13 +63,14 @@ def wrapper(message, created_at_formatted_string):
5763 "operation_requested" : message .get ("operation_requested" , "unknown" ),
5864 ** process_diagnostics (diagnostics , file_key , message_id ),
5965 }
60- generate_and_send_logs (start_time , base_log_data , additional_log_data )
66+ generate_and_send_logs (start_time , base_log_data , additional_log_data , use_ms_precision = True )
6167
6268 return result
6369
6470 except Exception as error :
6571 additional_log_data = {"status" : "fail" , "statusCode" : 500 , "diagnostics" : str (error )}
66- generate_and_send_logs (start_time , base_log_data , additional_log_data , is_error_log = True )
72+ generate_and_send_logs (start_time , base_log_data , additional_log_data , use_ms_precision = True ,
73+ is_error_log = True )
6774 raise
6875
6976 return wrapper
0 commit comments