Skip to content

Commit

Permalink
refactor(ops): Optimize the iteration for filter_none_values and use …
Browse files Browse the repository at this point in the history
…logging.error to record logs when an exception occurs (#8461)
  • Loading branch information
hwzhuhao authored Sep 21, 2024
1 parent 1a8dcae commit 831c5a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions api/core/ops/entities/trace_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def ensure_type(cls, v):
return None
if isinstance(v, str | dict | list):
return v
else:
return ""
return ""


class WorkflowTraceInfo(BaseTraceInfo):
Expand Down
4 changes: 2 additions & 2 deletions api/core/ops/ops_trace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def add_trace_task(self, trace_task: TraceTask):
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()

Expand All @@ -727,7 +727,7 @@ def run(self):
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
Expand Down
7 changes: 5 additions & 2 deletions api/core/ops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@


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):
Expand Down

0 comments on commit 831c5a9

Please sign in to comment.