feat: record the observability fields end to end through telemetry
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
① 结构性失败(建池/建表)→ warning 一次后永久降级(池置 None 短路);
|
||||
② 运行时单条写失败 → 逐条 warning 丢弃,不降级不重试(连接抖动由
|
||||
asyncpg 池自恢复;避免浸泡开头一次抖动导致后续全程失遥测)。
|
||||
构造不连库(lazy),18 列 schema 与 SQLite 版同名同序。
|
||||
构造不连库(lazy),20 列 schema 与 SQLite 版同名同序。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -39,10 +39,18 @@ CREATE TABLE IF NOT EXISTS llm_calls (
|
||||
cache_hit BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
error TEXT,
|
||||
cost DOUBLE PRECISION,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
cached_prompt_tokens INTEGER,
|
||||
model_reported TEXT
|
||||
);
|
||||
"""
|
||||
|
||||
# 新列排在 created_at 之后: 与旧表 ALTER 追加的位置一致(见 sqlite.py 同款注释)
|
||||
_BACKFILL = (
|
||||
"ALTER TABLE llm_calls ADD COLUMN IF NOT EXISTS cached_prompt_tokens INTEGER",
|
||||
"ALTER TABLE llm_calls ADD COLUMN IF NOT EXISTS model_reported TEXT",
|
||||
)
|
||||
|
||||
_COLUMNS = (
|
||||
"call_id",
|
||||
"parent_call_id",
|
||||
@@ -62,6 +70,8 @@ _COLUMNS = (
|
||||
"cache_hit",
|
||||
"error",
|
||||
"cost",
|
||||
"cached_prompt_tokens",
|
||||
"model_reported",
|
||||
)
|
||||
|
||||
_INSERT = (
|
||||
@@ -104,6 +114,9 @@ class PostgresRecorder:
|
||||
self._pool = await asyncpg.create_pool(self._dsn, timeout=10)
|
||||
async with self._pool.acquire() as conn:
|
||||
await conn.execute(_DDL)
|
||||
for statement in _BACKFILL:
|
||||
# 已存在的旧表补新列(issue #3);ADD COLUMN IF NOT EXISTS 原生幂等
|
||||
await conn.execute(statement)
|
||||
self._schema_ready = True
|
||||
return self._pool
|
||||
except asyncio.CancelledError:
|
||||
|
||||
Reference in New Issue
Block a user