fix: enrich workflow run observability

This commit is contained in:
2026-06-22 14:36:54 +08:00
parent 30ee1551c7
commit 75a7671a27
3 changed files with 46 additions and 4 deletions
@@ -195,6 +195,37 @@ def _build_communication_metadata(
return communication
def _copy_observability_metadata(
metadata: Dict[str, Any],
collaboration: Dict[str, Any],
communication: Optional[Dict[str, Any]] = None,
) -> None:
actor = (communication or {}).get('actor') or {}
for key in (
'agent_code',
'agent_name',
'branch_id',
'branch_label',
'collaboration_mode',
'collaboration_role',
'model',
'model_id',
'model_name',
'node_label',
'node_type',
'provider_name',
'provider_type',
'subflow_name',
):
value = collaboration.get(key) or actor.get(key)
if value not in (None, '', {}, []):
metadata.setdefault(key, value)
channel = (communication or {}).get('channel')
if channel:
metadata.setdefault('channel', channel)
def _resolve_handoff_target(
current_node_id: str,
result: Optional[NodeResult],
@@ -237,7 +268,7 @@ def _make_execution_log_entry(
collaboration['branch_label'] = branch_label or branch_id
if collaboration:
metadata['collaboration'] = collaboration
metadata['communication'] = _build_communication_metadata(
communication = _build_communication_metadata(
node_map,
node_id,
node_type,
@@ -249,8 +280,14 @@ def _make_execution_log_entry(
output=extra.get('output'),
error=extra.get('error'),
)
metadata['communication'] = communication
_copy_observability_metadata(metadata, collaboration, communication)
metadata['communication']['timestamp'] = extra.get('timestamp')
waiting_config = extra.get('waiting_config') or extra.get('config')
if waiting_config:
metadata.setdefault('waiting_config', waiting_config)
entry = {
'type': event_type,
'node_id': node_id,
'node_type': node_type,
'node_label': _node_label_from_map(node_map, node_id),
@@ -306,7 +343,7 @@ def _make_stream_event_log_entry(event: Dict[str, Any]) -> Optional[dict]:
output = event_data.get('content') or event_data.get('message')
error = event_data.get('error_message') or event_data.get('error')
return {
entry = {
'type': event_type,
'node_id': node_id,
'node_type': node_type,
@@ -325,6 +362,8 @@ def _make_stream_event_log_entry(event: Dict[str, Any]) -> Optional[dict]:
'communication': communication,
},
}
_copy_observability_metadata(entry['metadata'], collaboration, communication)
return entry
def _log_timestamp(log: Dict[str, Any]) -> str:
@@ -1705,6 +1744,7 @@ class AIWorkflowService:
elapsed_time=elapsed,
metadata=_node_result_metadata(result),
events=_node_result_events(result),
waiting_config=result.waiting_config,
loop_iteration=iteration,
))
@@ -2149,6 +2189,7 @@ class AIWorkflowService:
elapsed_time=elapsed,
metadata=_node_result_metadata(result),
events=_node_result_events(result),
waiting_config=result.waiting_config,
inputs=copy.deepcopy(node_inputs),
target_node_id=target_node_id,
)
@@ -2682,6 +2723,7 @@ class AIWorkflowService:
elapsed_time=elapsed,
metadata=_node_result_metadata(result),
events=_node_result_events(result),
waiting_config=result.waiting_config,
target_node_id=target_node_id,
)
logs.append(log_entry)
@@ -2536,7 +2536,7 @@
"version": "版本",
"draft": "草稿",
"timeline": "执行时间线",
"events": "????",
"events": "运行事件",
"noLogs": "暂无执行日志",
"inputsOutputs": "输入 / 输出"
}
@@ -2536,7 +2536,7 @@
"version": "版本",
"draft": "草稿",
"timeline": "執行時間線",
"events": "????",
"events": "執行事件",
"noLogs": "暫無執行日誌",
"inputsOutputs": "輸入 / 輸出"
}