--- title: "Logfire" created: 2026-06-10 updated: 2026-06-10 type: concept tags: [observability, open-telemetry, pydantic, agent, drift-detection] sources: [raw/articles/pydantic-three-piece-suite-2026.md] --- # Logfire > 基于 [[open-telemetry|OpenTelemetry]] 标准的可观测平台,由 [[pydantic|Pydantic]] 团队开发。核心价值:4 行代码拿到完整 Agent span 树 + 数据不锁定厂商 + SQL 查询 trace。 ## 4 行代码接入 ```python import logfire from pydantic_ai import Agent logfire.configure() logfire.instrument_pydantic_ai() agent = Agent('openai:gpt-4o', instrument=True) ``` 自动记录的 span 树: ``` agent.run (根,总耗时 + token 成本) ├── chat gpt-4o (model request) ├── tool.search_weather (参数 + 返回) ├── tool.web_search └── chat gpt-4o (follow-up) ``` ## 漂移检测 Logfire 的核心价值不是 UI——而是 **[[drift-detection|漂移检测]]**。当你用传统日志只能看到"第 47 次报错了"时,Logfire 让你在"第 32 次开始不对劲"时就看到趋势。 案例:Sophos 安全团队发现 Agent tool 调用频率从每 50 次推理 1 次涨到每 8 次 1 次——用 SQL 查询 trace 发现的,传统日志看不出来。 ## OTel 标准优势 - 数据不锁定厂商:可自托管,可导出到 Grafana/Jaeger - 可架 OpenTelemetry Collector 做数据清洗/采样 - 标准语义:`gen_ai.operation.name`、`gen_ai.usage.input_tokens` 等框架层自动遵守 ## 部署选项 - SaaS:$49/mo 起(10M records/month) - 自托管:OTel Collector 前置,多后端分发 ## 参考 - [[open-telemetry|OpenTelemetry]] - [[drift-detection|漂移检测]] - [[agent-observability|Agent 可观测性]] - [[pydantic-three-piece-suite|Pydantic 三件套]]