Observability · Detailed guide · verified 2026-08-28

logfire:Detailed Guide

OpenTelemetry-native observability for AI/LLM systems and Python apps: logs, traces and metrics in one place.

logfire Detailed Guide

Version 4.41.0~4.41.0 | category metrics | security (reviewed) | sources: official project docs (English README/docs) + measured in this marketplace (2026-08-28)
Companion: site docs (manifest + guide + evidence) | quick version: site docs

1. When to use it

Logfire (by the Pydantic team, MIT, ~4.4k stars) is an observability platform for AI/LLM/agent systems: natively collects LLM calls, token usage, latency and cost via OpenTelemetry, with dashboards and queries. Dual form of CLI + Python library, supporting a local preview (token-free) and a hosted platform for uploads.

In one sentence: give LLM apps a "monitoring screen" — how much each call costs, how slow it is, and which step failed, all at a glance.

You want observability for your Python app — traces, spans, metrics — without building a whole observability stack; Logfire is OpenTelemetry-based observability for Python. The two things people trip on: the first install is slow (opentelemetry dependency family, 3-5 minutes — normal, not stuck), and the "must log in?" question — local preview runs without any token (verified), only uploading to the hosted platform needs logfire auth.

When to use it:

  • Tracing Python apps with minimal code (logfire.configure + instrument_*);
  • Local preview of traces/spans without accounts;
  • Uploading to the hosted platform with token auth.

When not to use it: you need a self-hosted full observability stack with your own retention/policies.

2. Capability list

CapabilityPurpose
LLM call tracingmodel/token/latency/cost per call
Automatic instrumentationopenai/anthropic/langchain etc. integrations (logfire.instrument_*)
Local previewtoken-free local trace viewing
Hosted platformmulti-environment dashboards, alerts, queries
Cost/usage metricsSee the agent-executable guide
OpenTelemetry integrationSee the agent-executable guide

3. Quick install

note: verified path here; mainland must use the Tsinghua mirror (PyPI official timeout)
# Source: Trove detailed guide · verified 2026-08-28
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple logfire==4.41.0
logfire --version

Expected output: Running Logfire 4.41.0 with CPython ...

Step 1: Confirm the library imports and configures

Why: import logfire + configure without errors means the library is installed complete and the dependency chain is fine; local preview mode passes this line without a token.

# Source: Trove detailed guide · verified 2026-08-28
python3 -c "import logfire; logfire.configure; print('logfire configured: OK')"

Expected output: logfire configured: OK (local preview runs without a token)

Stuck? How to recover:

  • import fails → confirm pip and python3 share the same environment (activate the venv first);
  • token error → local preview does not need a token; skip auth.

Step 2: Confirm the CLI and optional connectivity surface

Why: logfire --version confirms the CLI; when uploading to the hosted platform, logfire auth then checking ~/.logfire/ for a token confirms the auth path.

# Source: Trove detailed guide · verified 2026-08-28
logfire --version

Expected output: Running Logfire 4.41.0 with CPython ...

Stuck? How to recover:

  • auth interactive stuck → use --non-interactive or the device-code flow;
  • preview port taken → see global options in --help (--base-url/--region etc.).

Install variants

PathCommandMeasured
Main path (measured)pip install -i https://pypi.tuna.tsinghua.edu.cn/simple logfire==4.41.0 && logfi...✅ measured in this marketplace
Mirror/proxySee quick guide and semi_auto_note; for China installs follow the logfire guidemeasured
Semi-auto note: measured command = pip install -i Tsinghua mirror logfire==4.41.0 (verified in this environment 2026-08-28, isolated venv, Python 3.14); China installs must use the Tsinghua mirror (official PyPI times out); depends on the full opentelemetry family, first install ~3-5 minutes; uploading to the hosted platform needs logfire auth login (token in ~/.logfire/), local preview mode works token-free; no resident daemon
  • Install time: opentelemetry family deps, first install 3-5 minutes is normal, not stuck; mainland must use the Tsinghua mirror prefix.
  • Windows / macOS: pip install and instrumentation code are the same; token and config also go to ~/.logfire/.
  • Data egress: telemetry does not leave the machine without login/local preview; uploading to the hosted platform needs a token (writes ~/.logfire/).
  • Write surface: only ~/.logfire/ (own directory, no shared registration surface); co-install judged all possible-compatible.

4. Why this happens (mechanism & shared surface)

pip installs logfire==4.41.0 (Python >= 3.10; opentelemetry family deps, first install 3-5 minutes — normal). logfire.configure is the instrumentation entry; local preview mode runs without a token; logfire auth stores the token in ~/.logfire/ for uploading telemetry.

Key concepts:

  • configure: instrumentation entry point;
  • preview: local preview of traces/spans (no token);
  • auth: browser/device-code login (token stored in ~/.logfire/).

Where it writes: ~/.logfire/ (own directory, no shared registration surface).

  • ~/.logfire/: dedicated config/token (generated, measured)
  • Inside the codebase: OpenTelemetry instrumentation (logfire.instrument_* calls, code-level integration)
  • Runtime: CLI commands (preview/auth), no resident daemon

5. Common operations

Step 1: Install the package (why pin the version: 4.41.0 is the verified collection version)

Why: logfire depends on the opentelemetry family; the first install takes 3-5 minutes — be patient, it is not stuck. Mainland PyPI official times out, so the Tsinghua mirror prefix is required.

# Source: Trove detailed guide · verified 2026-08-28
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple logfire==4.41.0
logfire --version

Expected output: Running Logfire 4.41.0 with CPython ...

# Source: Trove detailed guide · verified 2026-08-28
logfire --help

Expected output: full CLI docs

After install, confirm:

  • --version prints 4.41.0;
  • logfire --help has full CLI docs.

Stuck? How to recover:

  • install takes long → opentelemetry deps are many, normal (first 3-5 minutes); confirm the Tsinghua mirror prefix;
  • Python version → confirm >= 3.10.

Step 2: Code instrumentation smoke (local preview, no token)

Why: logfire.configure is the instrumentation entry; local preview mode runs without a token — verify the library works first, then decide whether to connect the hosted platform.

# Source: Trove detailed guide · verified 2026-08-28
python3 -c "import logfire; logfire.configure; print('logfire configured: OK')"

Expected output: logfire configured: OK (local preview runs without a token)

After install, confirm:

  • prints logfire configured: OK, no auth error.

Stuck? How to recover:

  • token error → local preview does not need a token; if it prompts to log in, use logfire preview or skip auth;
  • import fails → confirm pip and python3 share the same environment.

Step 3: Login to the hosted platform + local preview (optional)

Why: logfire auth goes through browser/device-code login (token stored in ~/.logfire/), needed only for uploading telemetry; logfire preview starts a local preview to view traces/spans.

# Source: Trove detailed guide · verified 2026-08-28
logfire auth

Expected output: browser/device-code login flow (interactive; token stored in ~/.logfire/)

# Source: Trove detailed guide · verified 2026-08-28
logfire preview

Expected output: local preview address (view traces/spans; Ctrl+C to exit)

After install, confirm:

  • after auth, ~/.logfire/ has a token;
  • preview opens the preview address.

Stuck? How to recover:

  • auth interactive stuck → use --non-interactive or the device-code flow;
  • preview port taken → see global options in --help (--base-url/--region etc.).

Startup and entry

  • Instrumentation: logfire.configure in code + instrument_* calls;
  • CLI: logfire --help (auth/preview etc.).

Common operations

Operation 1: Code instrumentation smoke (local preview, no token; verified here)

# Source: Trove detailed guide · verified 2026-08-28
python3 -c "import logfire; logfire.configure; print('logfire configured: OK')"

Expected output: logfire configured: OK (local preview runs without a token)

Operation 2: Login to the hosted platform (only needed for uploading)

# Source: Trove detailed guide · verified 2026-08-28
logfire auth

Expected output: browser/device-code login flow (interactive; token stored in ~/.logfire/)

Operation 3: Local preview

# Source: Trove detailed guide · verified 2026-08-28
logfire preview

Expected output: local preview address (view traces/spans; Ctrl+C to exit)

Data and directories

  • Token/config: ~/.logfire/;
  • In-code: logfire.instrument_* / logfire.configure calls (project code, not auto-removed).

6. Conflict pairs (summary)

Same source as the tool-page matrix — 19 pairs total (5 measured compatible / 14 inferred possibly compatible / 0 inferred possibly conflicting); full pairs, states and evidence: Conflict pairs (co-install matrix).

7. Quick troubleshooting

  • No standalone handbook yet; for install/uninstall issues first see the agent-executable guide notes

8. Uninstall and residue check

# Source: Trove detailed guide · verified 2026-08-28
pip uninstall -y logfire logfire-api 2>/dev/null || true; rm -rf ~/.logfire
note: pip uninstall + remove ~/.logfire; in-code instrumentation is project code, not auto-deleted
# Source: Trove detailed guide · verified 2026-08-28
pip uninstall -y logfire logfire-api 2>/dev/null || true
rm -rf ~/.logfire
command -v logfire >/dev/null 2>&1 && echo "残留: logfire 仍存在" || echo "logfire removed: OK"

Expected output: logfire removed: OK

Manual checklist (code changes, not auto-deleted):

  • logfire.instrument_* / logfire.configure calls in the codebase (OpenTelemetry instrumentation code)
  • logfire dependency in pyproject/requirements (pip uninstall handled the local environment; project files need manual removal)

9. FAQ

  • Runtime preflight (needs Python >= 3.10)
  • Official pip path (measured here); China installs must use the Tsinghua mirror (official PyPI times out); depends on the full opentelemetry family, first install 3-5 minutes
  • For instrumentation-API only, install logfire-api (lightweight); uploading to the hosted platform needs logfire auth login (token in ~/.logfire/); local preview mode works token-free
  • Each operation = one command block + expected output
  • Heavy deps: full opentelemetry family, first install 3-5 minutes; China pip must use the Tsinghua mirror
  • Q: Do I have to log in? A: No. Local preview mode runs without a token; only uploading to the hosted platform needs logfire auth.
  • Q: Install very slow? A: opentelemetry deps are many, normal (first 3-5 minutes); use the Tsinghua mirror prefix domestically.
  • Q: Will telemetry data leave my machine? A: only when uploading to the hosted platform (token auth); no login/local preview = no egress. Watch data compliance in production.
  • Q: Conflicts with other plugins? A: judged all possible-compatible — logfire only writes ~/.logfire/ (own), no shared registration surface.
  • Q: Where to report problems? A: install/uninstall issues on this marketplace go through the entry feedback channel (usage-report template); project issues go to the author's repository.
  • Version: [4.41.0, 4.41.0] locked (verified collection version).
  • Environment: Python >= 3.10; opentelemetry family deps (first install 3-5 minutes).
  • Network: PyPI official times out, must use the Tsinghua mirror.
  • Write surface: ~/.logfire/ (own, no shared registration surface).
  • Data egress: only when uploading to the hosted platform (token auth); no login/local preview = no egress.
  • Co-install: judged all possible-compatible — logfire only writes ~/.logfire/ (own), no shared registration surface.

10. Sources

  • Verified: local repro log 2026-08-29 (2026-08-29, install + version + instrumentation smoke).
  • Not tested: hosted platform upload (needs token); local preview long-run (per project needs).

External tutorials (unverified)

Third-party tutorials are not individually verified; check against this page and official docs.

  • 官方 README:安装与认证(pip install / logfire auth / 首次运行行为) [官方文档 · logfire 官方 · 2026-08-30(v4.41.0 README)]
    `pip install logfire` → `logfire auth` 认证(浏览器 OAuth;或设 `LOGFIRE_TOKEN` 环境变量走 write token)→ 代码里 `logfire.configure` 后开测
  • 官方 README:手动 tracing API(configure / info / span / debug) [官方文档 · logfire 官方 · 2026-08-30(v4.41.0 README)]
    手动埋点三件套——`logfire.configure` 初始化、`logfire.info('Hello, {name}!', name=...) ` 结构化日志({} 占位符)、`with logfire.span('...{question}...'):` 追踪块(span 内 debug/info 自动归属);日期等类型自动格式化
  • 官方 CLI:命令面(info / run / projects / read-tokens / inspect / gateway 等) [官方文档 · logfire 官方 · 2026-08-30(v4.41.0)]
    CLI 命令——auth(认证)/ clean(清空本地数据目录)/ gateway(本地 OAuth 代理,AI Gateway)/ inspect(检查已装包并推荐有用集成)/ whoami(当前用户与项目 URL)/ projects / read-tokens(项目读 token)/ prompt(生成给 LLM 的提示,面向 Logfire MCP)/ info(版本与环境)/ run(带 Logfire 插桩跑 Python 脚本);global 选项 --non-interactive / --base-url(自托管)/ --region us|eu
  • 官方 README:集成(FastAPI 等生态) [官方文档 · logfire 官方 · 2026-08-30(v4.41.0 README)]
    不手动埋点也可用集成——`logfire.instrument_fastapi(app)` 一键插桩 FastAPI(数据库连接器/http 库/logging handler 同理);README 说支持很多流行包(文档页 integrations)

Merged sources

This page merges multiple source articles — deduplicated by content hash, measured, and rewritten by AI. Sources are not scattered; they all live on this single page.

No merged sources yet: this page distills local verification and community rewrites; provenance details live on the linked solution page.

← Back to logfire solution page | Observability domain