lili
|
958f78f523
|
feat(obs): 阶段四观测面二 Python 侧 token metric——llm_tokens{kind} + llm_cache_hit_rate
contract-gates / contract-gates (push) Has been cancelled
docs-gate / docs-gate (push) Has been cancelled
补面五(game-cloud GenMetrics)拿不到的两个纯 Python 侧 token 维度 metric:
llm_tokens(Counter,kind=input/output/cached)与 llm_cache_hit_rate(Histogram,
每 run 命中率 [0,1])。复用波③ 既有 OTLP 基础设施(开关 CHEAP_OTLP_ENDPOINT、
端点解析、代理旁路、service.name=cheap-gen-worker、best-effort 铁律),换 OTLP
metrics 通道;默认关字节不变、绝不咬生成、与面五 5 个 metric 零重叠不双计。
关键约束(主控亲验坐实):生产 Service 路拿不到 cached——trace.py 组 cost.tokens
只填 in/out,agentscope ModelCallEndEvent 只有 input_tokens/output_tokens 无
cached 字段。故 Service 路(on_reply 只读嗅探 in/out、_metric_emitted 幂等)传
cached=None 如实降级:只发 input/output 计数,不发 cached 计数与 cache_hit_rate,
绝不塞 0 伪造命中率。CLI/批跑路(RecordingOpenAIChatModel.records[2])cached 可得、
两 metric 全发。生产 Service 路发 cached 需 per-POST RecordingModel 或 tier2
breaker 存 cached token,均超本次最小改动边界,列 follow-up。
主控终审:亲跑 tests/test_cheap_otlp_sink.py + test_cheap_service_app.py 29 passed、
全量回归 392 passed/1 skipped;逐条读承重 diff(默认关守卫/best-effort/不双计/
cached 诚实降级/MeterProvider 进程单例防线程泄漏/cached 截 [0,input]/除零守卫)。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-07-05 23:57:40 -07:00 |
|
lili
|
5b34807e73
|
feat(cheap): 面四 Python 三跳 traceparent 打通——便宜档生成串成单条 trace 树(观测阶段四)
contract-gates / contract-gates (push) Has been cancelled
docs-gate / docs-gate (push) Has been cancelled
Java agent(面一b)已在派发出网自动注 traceparent;本片补 Python 侧三个断点,让一次便宜档生成
在 Tempo 里是 Java→worker(:9501)→cheap-service(:8300)生成 的单条 trace 树而非散落 root:
- 断点①:worker_service.do_POST 抓入站 traceparent 进 job._otelCarrier(self.headers 仅此可得);
process_job 用 worker_span_scope 在入站 context 下建 worker SERVER span、包住真生成调用(span 建在
真处理 job 的 worker 线程,非只入队即 202 的 do_POST)。
- 断点②:driver 读当前 context(worker span 经 asyncio.run 透传进协程)inject 成 W3C carrier,随出站
:8300 各 POST header 带上;同份 carrier 写会话 sidecar。
- 断点③:/chat reply 在 AgentScope 后台任务跑、与 HTTP 请求解耦读不到实时 context——故走既有 C2 sidecar
桥:cheap_service_app 工厂读 sidecar traceparent → parent_carrier → CheapOtlpSink 每步生成 span 挂入站
context 当子 span(不再私有 root)。
传播 helper 集中 cheap_otlp_sink(extract/inject/worker_span_scope);全程 best-effort(otel 不可用/carrier
坏/Collector 不可达都退化成少串一段 trace、生成异常原样穿出)、CHEAP_OTLP_ENDPOINT 默认关时零行为变化
(parent=None 退私有 root、sidecar 不写 traceparent 字节不变)、代理旁路红线未破、业务 traceId 并存(§10 决策5)。
test_trace_propagation.py 14 例(含端到端三跳单条 trace 树,InMemorySpanExporter 证父子链+同 trace_id)
+ test_worker_service +2;主控亲跑 40 passed(3 文件)+ 全量 364 passed 1 skipped 无回退。
真跨进程 Tempo trace 树验证 = dev 开 CHEAP_OTLP_ENDPOINT 重跑 follow-up。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-07-05 20:30:04 -07:00 |
|
lili
|
daa49e5864
|
feat(obs): 便宜档主生成路 OTLP span sink + 双入口 fan-out 并接(阶段四观测 波③ T3-1)
contract-gates / contract-gates (push) Has been cancelled
docs-gate / docs-gate (push) Has been cancelled
便宜档 Service(cheap_service_app)+ CLI(cheap_studio)主生成路此前只经 make_jsonl_sink
写 trace.jsonl、不产 OTLP span,观测栈 Tempo 看不到便宜档生成。新接 cheap_otlp_sink:与
make_jsonl_sink 同签名,把每步 TraceStep 推成 OTLP span 发 mini-infra Collector
(service.name=cheap-gen-worker),span 属性映射对齐 tier2 studio_sink 的标准 gen-ai 键。
- 默认关(env CHEAP_OTLP_ENDPOINT / infra_config 取不到即 no-op),build_trace_sink 原样返回
jsonl sink、现有行为字节不变;开则 fan-out(jsonl 先落盘照旧、OTLP 额外发一份,各 best-effort)。
- best-effort 铁律:缺 otel / Collector 不可达 / 发送失败 → 记一次告警、永久降级 no-op、绝不抛、
绝不咬生成主链(设计 §8);observe-only 从不回写生成/门判定字段。
- 惰性 import otel(顶层零重依赖,对齐 build_cheap_app 惰性红线)+ 代理旁路(T3-4,建 exporter 前
把 Collector host 并入 NO_PROXY,绕 clash fake-ip)。
- provider 做进程级共享单例(非 per-run):长驻 Service 中间件工厂 per-turn 建 sink,per-run 会逐局
泄漏后台上报线程;trace_id 只作 per-span 属性,BatchSpanProcessor 一条后台线程跨局复用,atexit 兜底 flush。
- 双入口都接(Service :273 + CLI :214),fan-out 不破坏既有 jsonl 落盘。
终审(亲跑非照搬):cheap-worker/.venv 全套 350 passed/1 skipped(含 span sink 11 例)、零回归、
py_compile 三文件过、docs-gate 七检绿。跨机 OTLP 命门已验(mini-desktop→mini-infra:4318=200)。
真发 Collector→Tempo 见 span 排 mini-desktop 起服务后验。
T3-3 metrics 空口按红线#7(不留孤儿)剔除:本波无生产调用方,真值填充随波⑤ T5-2 带埋点调用方一起落。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
2026-07-05 09:16:16 -07:00 |
|