-- 全链 Trace(Mastra Observability 的 span 落库): -- 工作流 = 一个 trace;节点实例 = 一个 span;活动内的步骤 / 工具 / 模型 / 人卡 = 子 span。 -- 我们的执行不经 Mastra 图,所以 span 是**手动打**的 —— 经 Mastra 的 Observability -- 组件产出标准 span,再由自定义 exporter 落这张表(留痕只增不改,与任务记忆并行不替代)。 create table if not exists sys.trace_span ( id text primary key, trace_id text not null, parent_id text, name text not null, kind text not null, /** 归属:一条 trace 就是一条工作流;节点/任务能对上就填上 */ workflow_id text, node_id text, task_id text, input jsonb, output jsonb, error jsonb, attributes jsonb, started_at timestamptz not null, ended_at timestamptz ); create index if not exists trace_span_trace_idx on sys.trace_span (trace_id, started_at); create index if not exists trace_span_workflow_idx on sys.trace_span (workflow_id, started_at);