Module audit

Module audit 

Source
Expand description

审计事件发射 helpers + JSONL 订阅层

§设计

所有 interface(grpc / rest / ws / mcp)把 auth 决策和下单事件都走同一组 helper,emit 的 tracing::event! 使用固定 target = "futu_audit"。这样:

  • 正常日志订阅(stderr / 文件)照常能看到它们(没过滤就全走)
  • 专用 audit JSONL 文件订阅层走 filter_fn(meta.target() == TARGET) 只收这些

JSONL 每条一行,字段固定 —— 字段顺序由 tracing-subscriber 的 json formatter 决定(level / timestamp / target / message / 其它 fields),方便 jq/duckdb 后处理。

§事件形状(field 命名)

字段含义
iface"grpc" / "rest" / "ws" / "mcp"
endpoint具体接口:路径 / proto_id / tool 名
key_idAPI key id,或 <missing> / <invalid>
outcome"allow" / "reject"
reasonreject 时的文字原因(allow 时也可选)
args_hash下单工具额外附:args 的 SHA-256 前 8 hex
scope校验的 scope(allow 时可选)

Constants§

TARGET
固定 target,供 tracing filter 使用

Functions§

allow
auth 通过事件(用 INFO 级别;debug 模式会看到量比较大,由 EnvFilter 过滤)
open_writer
打开 audit 输出路径,返回一个非阻塞 writer 和 guard(guard 必须活到进程退出)
reject
auth 拒绝事件
trade
交易事件(下单 / 改单 / 撤单)—— 无论 allow / reject 都记录