From 831c5a93af83058da71f56c2df1d634ee768e001 Mon Sep 17 00:00:00 2001 From: zhuhao <37029601+hwzhuhao@users.noreply.github.com> Date: Sat, 21 Sep 2024 22:56:37 +0800 Subject: [PATCH] refactor(ops): Optimize the iteration for filter_none_values and use logging.error to record logs when an exception occurs (#8461) --- api/core/ops/entities/trace_entity.py | 3 +-- api/core/ops/ops_trace_manager.py | 4 ++-- api/core/ops/utils.py | 7 +++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/core/ops/entities/trace_entity.py b/api/core/ops/entities/trace_entity.py index f27a0af6e0..db6ce9d9c3 100644 --- a/api/core/ops/entities/trace_entity.py +++ b/api/core/ops/entities/trace_entity.py @@ -21,8 +21,7 @@ class BaseTraceInfo(BaseModel): return None if isinstance(v, str | dict | list): return v - else: - return "" + return "" class WorkflowTraceInfo(BaseTraceInfo): diff --git a/api/core/ops/ops_trace_manager.py b/api/core/ops/ops_trace_manager.py index 876790f5b8..0200f4a32d 100644 --- a/api/core/ops/ops_trace_manager.py +++ b/api/core/ops/ops_trace_manager.py @@ -708,7 +708,7 @@ class TraceQueueManager: trace_task.app_id = self.app_id trace_manager_queue.put(trace_task) except Exception as e: - logging.debug(f"Error adding trace task: {e}") + logging.error(f"Error adding trace task: {e}") finally: self.start_timer() @@ -727,7 +727,7 @@ class TraceQueueManager: if tasks: self.send_to_celery(tasks) except Exception as e: - logging.debug(f"Error processing trace tasks: {e}") + logging.error(f"Error processing trace tasks: {e}") def start_timer(self): global trace_manager_timer diff --git a/api/core/ops/utils.py b/api/core/ops/utils.py index 498685b342..3cd3fb5756 100644 --- a/api/core/ops/utils.py +++ b/api/core/ops/utils.py @@ -6,12 +6,15 @@ from models.model import Message def filter_none_values(data: dict): + new_data = {} for key, value in data.items(): if value is None: continue if isinstance(value, datetime): - data[key] = value.isoformat() - return {key: value for key, value in data.items() if value is not None} + new_data[key] = value.isoformat() + else: + new_data[key] = value + return new_data def get_message_data(message_id):