-
Notifications
You must be signed in to change notification settings - Fork 0
[Priority: Low] [Ops] 设计并实现 trace context 透传与日志关联 #376
Copy link
Copy link
Open
Labels
status:todoPlanned but not startedPlanned but not started
Description
🔍 发现的问题 / 原始需求描述
- 与 metrics export 不同,当前链路里仍缺少明确的 trace context 透传和日志关联策略。
- 一旦出现跨 inbound A2A、OpenCode upstream、peer A2A call 的问题,单靠 task id 或 debug log 很难还原完整链路。
- 该能力适合独立为小步实现,不应和
/metrics一起绑定。
🛠️ 详细实施方案
- 涉及文件:
src/opencode_a2a/client/request_context.py - 涉及文件:
src/opencode_a2a/client/client.py - 涉及文件:
src/opencode_a2a/server/application.py - 涉及文件:
src/opencode_a2a/opencode_upstream_client.py - 涉及文件:
docs/guide.md - 涉及文件:
tests/client/test_request_context.py - 涉及文件:
tests/server/test_call_context_builder.py - 涉及文件:
tests/upstream/test_opencode_upstream_client_params.py - 支持读取并透传
traceparent/tracestate,在缺失时生成本地 trace id,并把关联信息写入现有日志上下文。 - 明确 trace context 在 inbound A2A -> OpenCode upstream -> outbound peer A2A 三段链路中的传播边界。
- 核心逻辑 / 伪代码:
traceparent = inbound.headers.get("traceparent") or generate_traceparent()
request.state.traceparent = traceparent
forward traceparent to upstream OpenCode and peer A2A requests
include trace_id in metric log labels / request logs
🧪 回归测试建议
- 增加已有
traceparent透传测试和无 header 自动生成测试。 - 确认不会覆盖用户显式传入的自定义请求头。
- 运行
./scripts/doctor.sh。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status:todoPlanned but not startedPlanned but not started