refactor(ops): Optimize the iteration for filter_none_values and use logging.error to record logs when an exception occurs (#8461)

This commit is contained in:
zhuhao 2024-09-21 22:56:37 +08:00 committed by GitHub
parent 1a8dcae10e
commit 831c5a93af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View File

@ -21,8 +21,7 @@ class BaseTraceInfo(BaseModel):
return None return None
if isinstance(v, str | dict | list): if isinstance(v, str | dict | list):
return v return v
else: return ""
return ""
class WorkflowTraceInfo(BaseTraceInfo): class WorkflowTraceInfo(BaseTraceInfo):

View File

@ -708,7 +708,7 @@ class TraceQueueManager:
trace_task.app_id = self.app_id trace_task.app_id = self.app_id
trace_manager_queue.put(trace_task) trace_manager_queue.put(trace_task)
except Exception as e: except Exception as e:
logging.debug(f"Error adding trace task: {e}") logging.error(f"Error adding trace task: {e}")
finally: finally:
self.start_timer() self.start_timer()
@ -727,7 +727,7 @@ class TraceQueueManager:
if tasks: if tasks:
self.send_to_celery(tasks) self.send_to_celery(tasks)
except Exception as e: except Exception as e:
logging.debug(f"Error processing trace tasks: {e}") logging.error(f"Error processing trace tasks: {e}")
def start_timer(self): def start_timer(self):
global trace_manager_timer global trace_manager_timer

View File

@ -6,12 +6,15 @@ from models.model import Message
def filter_none_values(data: dict): def filter_none_values(data: dict):
new_data = {}
for key, value in data.items(): for key, value in data.items():
if value is None: if value is None:
continue continue
if isinstance(value, datetime): if isinstance(value, datetime):
data[key] = value.isoformat() new_data[key] = value.isoformat()
return {key: value for key, value in data.items() if value is not None} else:
new_data[key] = value
return new_data
def get_message_data(message_id): def get_message_data(message_id):