Files
myWiki/concepts/logfire.md

1.7 KiB
Raw Blame History

title, created, updated, type, tags, sources
title created updated type tags sources
Logfire 2026-06-10 2026-06-10 concept
observability
open-telemetry
pydantic
agent
drift-detection
raw/articles/pydantic-three-piece-suite-2026.md

Logfire

基于 open-telemetry 标准的可观测平台,由 pydantic 团队开发。核心价值4 行代码拿到完整 Agent span 树 + 数据不锁定厂商 + SQL 查询 trace。

4 行代码接入

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.namegen_ai.usage.input_tokens 等框架层自动遵守

部署选项

  • SaaS$49/mo 起10M records/month
  • 自托管OTel Collector 前置,多后端分发

参考