feat(observability): 트레이스에 model(metadata) + 사용 태그 — skill:<이름> / wiki / mcp:<함수>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
823292cbb6
commit
727486e7cb
@@ -88,8 +88,9 @@ async def test_finalize_sends_user_trace(lf_server, django_user_model, monkeypat
|
||||
async def _msgs(_sid):
|
||||
tool = {"type": "tool", "tool": "sap-icf_get_program_source", "state": {"status": "completed", "input": {"program_name": "ZTEST"}, "output": "REPORT ztest.", "title": "ZTEST", "time": {"start": 1100, "end": 1300}}}
|
||||
bad = {"type": "tool", "tool": "read", "state": {"status": "error", "input": {"filePath": "x"}, "error": "no such file", "time": {"start": 1300, "end": 1310}}}
|
||||
return [{"info": {"role": "assistant"}, "parts": [tool, bad]},
|
||||
{"info": {"role": "assistant", "tokens": {"input": 3, "output": 4, "reasoning": 1}, "time": {"created": 1000, "completed": 1500}}, "parts": [{"type": "text", "text": "답"}]}]
|
||||
wiki = {"type": "tool", "tool": "read", "state": {"status": "completed", "input": {"filePath": "/workspace/wiki/programs/ZTEST.md"}, "output": "x", "time": {"start": 1310, "end": 1320}}}
|
||||
return [{"info": {"role": "assistant"}, "parts": [tool, bad, wiki]},
|
||||
{"info": {"role": "assistant", "modelID": "z-ai/glm-5.2", "tokens": {"input": 3, "output": 4, "reasoning": 1}, "time": {"created": 1000, "completed": 1500}}, "parts": [{"type": "text", "text": "답"}]}]
|
||||
|
||||
async def _sess(_sid):
|
||||
return {"title": "MARA 조회"}
|
||||
@@ -103,11 +104,14 @@ async def test_finalize_sends_user_trace(lf_server, django_user_model, monkeypat
|
||||
await asyncio.gather(*list(langfuse._pending))
|
||||
assert len(lf_server) == 1
|
||||
spans = lf_server[0]["body"]["resourceSpans"][0]["scopeSpans"][0]["spans"]
|
||||
assert [sp["name"] for sp in spans] == ["chat", "sap-icf_get_program_source", "read"]
|
||||
assert [sp["name"] for sp in spans] == ["chat", "sap-icf_get_program_source", "read", "read"]
|
||||
t = _attrs(spans[0])
|
||||
assert t["langfuse.user.id"] == "u@x.com" and t["langfuse.session.id"] == "ses_1"
|
||||
assert t["langfuse.trace.input"] == "질문" and t["langfuse.trace.output"] == "답"
|
||||
assert t["langfuse.observation.type"] == "generation" # 루트가 곧 답변 — 토큰은 여기
|
||||
assert t["llm.model_name"] == "z-ai/glm-5.2"
|
||||
meta = json.loads(t["metadata"])
|
||||
assert meta["model"] == "z-ai/glm-5.2" and meta["tags"] == ["codeassist", "mcp:get_program_source", "wiki"]
|
||||
assert json.loads(t["langfuse.observation.usage_details"]) == {"input": 3, "output": 5, "total": 8}
|
||||
a1, a2 = _attrs(spans[1]), _attrs(spans[2])
|
||||
assert spans[1]["parentSpanId"] == spans[0]["spanId"] and a1["langfuse.observation.type"] == "tool"
|
||||
@@ -131,3 +135,19 @@ async def test_phoenix_target_no_auth_and_openinference_attrs(lf_server):
|
||||
assert r["llm.model_name"] == "581" and r["llm.token_count.total"] == "10" and r["session.id"] == "s9" and r["user.id"] == "u@x.com"
|
||||
assert tl["openinference.span.kind"] == "TOOL" and tl["tool.name"] == "read" and json.loads(tl["input.value"]) == {"filePath": "a.md"}
|
||||
|
||||
|
||||
def test_usage_tags_skill_wiki_mcp():
|
||||
parts = [
|
||||
{"tool": "skill", "state": {"input": {"name": "classic-abap-fs"}}},
|
||||
{"tool": "read", "state": {"input": {"filePath": "/workspace/skills/abap-program-analyze/SKILL.md"}}},
|
||||
{"tool": "read", "state": {"input": {"filePath": "C:\\ws\\wiki\\programs\\Z.md"}}},
|
||||
{"tool": "sap-icf_get_table_fields", "state": {"input": {"table": "MARA"}}},
|
||||
{"tool": "sap-icf_get_program_source", "state": {"input": {"program_name": "Z"}}},
|
||||
{"tool": "read", "state": {"input": {"filePath": "/workspace/skills/classic-abap-fs/glossary.md"}}}, # SKILL.md 아님
|
||||
{"tool": "grep", "state": {"input": {"pattern": "x"}}}, # 태그 없음
|
||||
{"tool": "skill", "state": {"input": {"name": "classic-abap-fs"}}}, # 중복
|
||||
]
|
||||
assert langfuse.usage_tags(parts) == [
|
||||
"skill:classic-abap-fs", "skill:abap-program-analyze", "wiki", "mcp:get_table_fields", "mcp:get_program_source",
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user