instrumentation

Add Pydantic Logfire observability, tracing, and structured logging to Python, JavaScript, and Rust applications.

4.0k|282|Updated Dec 2, 2024
One-click install
npx skills add https://github.com/basicmachines-co/basic-memory --skill instrumentation-basicmachines-co
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: instrumentation
Source: https://github.com/basicmachines-co/basic-memory/tree/main/.agents/skills/instrumentation
Command: npx skills add https://github.com/basicmachines-co/basic-memory --skill instrumentation-basicmachines-co

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Setting up application observability is error-prone: misordered configure and instrument calls silently drop traces, missing package extras cause runtime failures, and unstructured log strings are not searchable. This Skill guides correct Logfire instrumentation so traces, logs, and metrics actually reach the dashboard. ## Core Features & Use Cases - Multi-language instrumentation: Configure Logfire SDKs for Python, JavaScript/TypeScript (Node.js, Cloudflare Workers, Next.js, Deno), and Rust with correct setup ordering. - Framework auto-instrumentation: Wire up instrumentors for FastAPI, Django, Flask, httpx, SQLAlchemy, asyncpg, Redis, Celery, and more, with the matching package extras. - AI/LLM observability: Capture LLM calls, token usage, tool invocations, and agent runs from PydanticAI, OpenAI, Anthropic, LiteLLM, DSPy, and Google GenAI. - Use Case: A developer building a FastAPI service with a PydanticAI agent asks to add observability; the Skill installs logfire[fastapi,pydantic-ai], places configure() before instrument calls, and adds structured logging with searchable attributes. ## Quick Start Ask the AI to add Logfire observability and tracing to your application, mentioning your language and frameworks.

Frequently Asked Questions about instrumentation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add Logfire observability to a Python application?▼

Install logfire with extras matching your frameworks, such as logfire[fastapi,httpx], then call logfire.configure() once in your entry point before any instrument_*() calls. Add structured logging with logfire.info() using {key} placeholders and keyword arguments.

How to instrument FastAPI with Logfire tracing?▼

Install the fastapi extra, call logfire.configure() first, then logfire.instrument_fastapi(app) passing your app instance. Web framework instrumentors require the app object, while HTTP client and database instrumentors like instrument_httpx() are global.

Does Logfire support JavaScript and TypeScript applications?▼

Yes, Logfire provides @pydantic/logfire-node for Node.js, @pydantic/logfire-cf-workers for Cloudflare Workers, and OpenTelemetry environment variable configuration for Next.js and Deno. Load the SDK before your app so it can auto-instrument common libraries.

Can Logfire monitor LLM calls from OpenAI or PydanticAI?▼

Yes, Logfire auto-instruments AI libraries including PydanticAI, OpenAI, Anthropic, LiteLLM, DSPy, and Google GenAI. Install the matching extra and call the corresponding instrument function to capture LLM requests, token usage, tool calls, and agent runs.

Why are my Logfire traces not appearing in the dashboard?▼

Traces are silently dropped when instrument_*() calls run before logfire.configure(), when LOGFIRE_TOKEN is not set, or when required package extras are missing. Verify ordering, run logfire auth, and confirm the correct extras are installed.

How do I use Logfire with Gunicorn workers?▼

Call logfire.configure() inside Gunicorn's post_fork hook rather than at module level, because each worker is a separate process. Place your instrument_*() calls in the same hook so every worker process is properly configured.