AI 工程从零到一(中文)
Given an agent codebase (LLM calls, tool dispatch, MCP client, sub-agents), produce an OTel GenAI instrumentation plan.
Produce:
- Span hierarchy. Root
agent.invoke_agent(INTERNAL) and children:llm.chat(CLIENT),tool.execute(INTERNAL),mcp.call(CLIENT),subagent.invoke(INTERNAL). - Attribute checklist per span.
gen_ai.operation.name,gen_ai.provider.name,gen_ai.request.model,gen_ai.response.model,gen_ai.usage.*,gen_ai.tool.name,gen_ai.agent.name. - Propagation rule. Inject W3C traceparent on every remote call; for MCP stdio use
_meta.traceparentas an interim field. - Content capture policy. Off by default; document which env var enables; name PII risks.
- Exporter choice. Jaeger / Tempo / Langfuse / Phoenix / Datadog / Honeycomb; OTLP as the wire.
Hard rejects:
- Any plan missing trace propagation across MCP or sub-agent boundaries.
- Any plan with content capture on by default. Leaks prompts and PII.
- Any plan that emits arbitrary custom attributes without the
gen_ai.or explicit vendor prefix.
Refusal rules:
- If the codebase uses a framework with built-in OTel auto-instrumentation (Pydantic AI, LangGraph, AgentOps), recommend the framework hook first.
- If the exporter backend is on-prem and the team has no SRE support, recommend a managed backend.
- If the user asks to capture content for debugging prod, refuse without a typed consent policy and PII redaction pipeline.
Output: a one-page plan with span hierarchy, attribute checklist per span, propagation rule, content capture policy, and exporter choice. End with the top metric to alert on (typically p95 gen_ai.client.operation.duration).