feat(observability): 트레이스에 model(metadata) + 사용 태그 — skill:<이름> / wiki / mcp:<함수>

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
lee-hyeon-cheol
2026-09-23 09:44:03 +09:00
co-authored by Claude Opus 5.5
parent 823292cbb6
commit 727486e7cb
3 changed files with 57 additions and 6 deletions
+5 -3
View File
@@ -228,6 +228,7 @@ async def _finalize(session: ChatSession, state: TurnState, started: float, *, f
usage: dict | None = None
title = state.title
tool_parts: list[dict] = []
model = ""
try:
msgs = await opencode_service.list_messages_a(session.id) or []
assistant = [m for m in msgs if (m.get("info") or {}).get("role") == "assistant"]
@@ -236,6 +237,7 @@ async def _finalize(session: ChatSession, state: TurnState, started: float, *, f
parts = assistant[-1].get("parts") or []
# 이 턴의 assistant 메시지가 여러 개(도구 왕복마다 하나)라 도구 파트는 전부 모음
tool_parts = [p for m in assistant for p in (m.get("parts") or []) if p.get("type") == "tool"]
model = info.get("modelID") or ""
full = "".join(p.get("text", "") for p in parts if p.get("type") == "text" and not p.get("synthetic"))
if full:
content = full
@@ -276,9 +278,9 @@ async def _finalize(session: ChatSession, state: TurnState, started: float, *, f
t0 = datetime.fromtimestamp(started, timezone.utc).isoformat()
root = langfuse.trace(
tid, "chat", userId=user_email, sessionId=session.id, input=state.user_text, output=content,
tags=["codeassist"], start=t0, end=langfuse.now_iso(),
usage=langfuse.usage_of(usage["input"], usage["output"]) if usage else None,
metadata={"elapsed_ms": usage["elapsed_ms"]} if usage else {}, error=failed,
tags=["codeassist", *langfuse.usage_tags(tool_parts)], start=t0, end=langfuse.now_iso(),
usage=langfuse.usage_of(usage["input"], usage["output"]) if usage else None, model=model,
metadata={"model": model, **({"elapsed_ms": usage["elapsed_ms"]} if usage else {})}, error=failed,
)
langfuse.send_later([root, *_tool_spans(tid, root, tool_parts)])
return usage, title