# Logfire — Python Observability on OpenTelemetry > Logfire is Pydantic’s Python SDK for traces/metrics/logs on OpenTelemetry, helping teams add observability with minimal code and query data with SQL. ## Install Save as a script file and run: ## Quick Use 1. Install: ```bash pip install logfire ``` 2. Authenticate (creates local credentials): ```bash logfire auth ``` 3. Verify: - Run the smallest example from the docs and confirm you can see at least 1 trace/span in the UI (or your chosen OTel backend). ## Intro Logfire is Pydantic’s Python SDK for traces/metrics/logs on OpenTelemetry, helping teams add observability with minimal code and query data with SQL. - **Best for:** Python teams who want quick, consistent observability for apps and agent backends - **Works with:** Python apps (e.g., FastAPI) and OpenTelemetry-compatible backends - **Setup time:** 10–30 minutes ## Practical Notes - Quant: aim for 1 end-to-end request trace with spans for DB + HTTP within the first hour. - Quant: track p95 latency and error rate before vs after adding instrumentation. ## Agent backend tip: make tool calls observable If you run an agent service, the fastest win is instrumenting tool calls: - external HTTP requests, - database queries, - vector search, - and model API calls. Name spans consistently (e.g., `tool.http`, `tool.sql`, `tool.vector`) so you can answer: *where did time and failures go?* ## Data hygiene Avoid logging secrets. Configure scrubbing/redaction early and review what ends up in traces before enabling in production. ### FAQ **Q: Is the whole platform open-source?** A: No. This repo is the open-source SDK and docs; the hosted platform is separate. **Q: Can I export to another backend?** A: Yes—OpenTelemetry compatibility means you can target other OTel backends if needed. **Q: What should I instrument first?** A: Start with request traces + tool calls, then add DB/HTTP client instrumentation. ## Source & Thanks > Source: https://github.com/pydantic/logfire > License: MIT > GitHub stars: 4,236 · forks: 234 --- ## 快速使用 1. 安装: ```bash pip install logfire ``` 2. 认证(生成本地凭据): ```bash logfire auth ``` 3. 验证: - 跑通文档的最小示例,确认至少 1 条 trace/span 出现在 UI(或你选用的 OTel 后端)。 ## 简介 Logfire 是 Pydantic 团队提供的 Python SDK,用 OpenTelemetry 统一采集 traces/metrics/logs,并以更少的改动获得可观测性;适合把调试、性能与错误定位变成可查询的工程化数据。 - **适合谁:** 希望快速把可观测性落地到应用/agent 后端的 Python 团队 - **可搭配:** Python 应用(如 FastAPI)与任意兼容 OpenTelemetry 的后端 - **准备时间:** 10–30 分钟 ## 实战建议 - 量化建议:1 小时内做到 1 条端到端请求 trace(至少含 DB + HTTP span)。 - 量化建议:对比接入前后 p95 延迟与错误率,观察收益与开销。 ## Agent 后端提示:把工具调用纳入可观测性 跑 agent 服务时,最快的收益来自把“工具调用”打点: - 外部 HTTP 请求、 - 数据库查询、 - 向量检索、 - 模型 API 调用。 给 span 统一命名(如 `tool.http`/`tool.sql`/`tool.vector`),才能快速回答“时间与失败都花在哪”。 ## 数据卫生 避免把密钥写进日志/trace。尽早配置脱敏规则,并在生产启用前复核落盘内容。 ### FAQ **整个平台都开源吗?** 答:不是。这个仓库是开源 SDK 与文档;平台端是独立产品。 **能导出到别的后端吗?** 答:可以。兼容 OpenTelemetry,通常能接入其他 OTel 后端。 **优先打点哪些?** 答:先做请求链路 + 工具调用,再补齐 DB/HTTP 客户端等自动化集成。 ## 来源与感谢 > Source: https://github.com/pydantic/logfire > License: MIT > GitHub stars: 4,236 · forks: 234 --- Source: https://tokrepo.com/en/workflows/logfire-python-observability-on-opentelemetry Author: Script Depot