From c97ef8166e4d17bcc461c9bad4c95409c0ea3055 Mon Sep 17 00:00:00 2001 From: Shahar Glazner Date: Sun, 2 Feb 2025 22:06:18 +0400 Subject: [PATCH] fix(api): logs (#3274) --- keep/api/core/db.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/keep/api/core/db.py b/keep/api/core/db.py index cf41bedc4..f1739bdd9 100644 --- a/keep/api/core/db.py +++ b/keep/api/core/db.py @@ -810,14 +810,18 @@ def push_logs_to_db(log_entries): if LOG_FORMAT == LOG_FORMAT_OPEN_TELEMETRY: for log_entry in log_entries: try: + try: + # after formatting + message = log_entry["message"][0:255] + except Exception: + # before formatting, fallback + message = log_entry["msg"][0:255] log_entry = WorkflowExecutionLog( workflow_execution_id=log_entry["workflow_execution_id"], timestamp=datetime.strptime( log_entry["asctime"], "%Y-%m-%d %H:%M:%S,%f" ), - message=log_entry["message"][ - 0:255 - ], # limit the message to 255 chars + message=message, context=json.loads( json.dumps(log_entry.get("context", {}), default=str) ), # workaround to serialize any object @@ -829,12 +833,16 @@ def push_logs_to_db(log_entries): else: for log_entry in log_entries: try: + try: + # after formatting + message = log_entry["message"][0:255] + except Exception: + # before formatting, fallback + message = log_entry["msg"][0:255] log_entry = WorkflowExecutionLog( workflow_execution_id=log_entry["workflow_execution_id"], timestamp=log_entry["created"], - message=log_entry["message"][ - 0:255 - ], # limit the message to 255 chars + message=message, # limit the message to 255 chars context=json.loads( json.dumps(log_entry.get("context", {}), default=str) ), # workaround to serialize any object