logfire-instrumentation

Add Pydantic Logfire observability to application code — traces, logs, metrics, and AI/agent spans. Use when the user asks to add or configure Logfire, observability, tracing, logging, or monitoring; maximize useful telemetry; or understand what an app is doing. Supports Python, JavaScript/TypeScript, Rust, and major AI agent frameworks including Pydantic AI, OpenAI Agents SDK, Claude Agent SDK, LangChain, LangGraph, CrewAI, AutoGen, and Google ADK. For infrastructure-only monitoring (hosts, Docker, Kubernetes, databases, or cloud metrics with no app-code changes), use `logfire-infrastructure`. For evaluating AI/agent behavior against test datasets, use `logfire-evals`.

Install
npx skills add 'https://github.com/pydantic/logfire/tree/main/logfire-sdk/logfire/.agents/skills/logfire-instrumentation'
Download bundle ↓
main · 39d1eb4Scanned 2026-09-17

Contributors

GitHub-linked commit authors for this SKILL.md at the saved revision. Co-authors and history before file renames are not included.

File history ↗
View on GitHub
← Back to SKILL.md

Python Integration Reference

Web Frameworks

FrameworkInstrumentorNeeds app instanceExtra
FastAPIlogfire.instrument_fastapi(app)Yesfastapi
Djangologfire.instrument_django()Nodjango
Flasklogfire.instrument_flask(app)Yesflask
Starlettelogfire.instrument_starlette(app)Yesstarlette
Any ASGI appapp = logfire.instrument_asgi(app)Yesasgi
Any WSGI appapp = logfire.instrument_wsgi(app)Yeswsgi

HTTP Clients

LibraryInstrumentorExtra
httpxlogfire.instrument_httpx()httpx
requestslogfire.instrument_requests()requests
aiohttp (client)logfire.instrument_aiohttp_client()aiohttp or aiohttp-client
aiohttp (server)logfire.instrument_aiohttp_server()aiohttp-server

Databases

LibraryInstrumentorExtra
asyncpglogfire.instrument_asyncpg()asyncpg
psycopglogfire.instrument_psycopg()psycopg
psycopg2logfire.instrument_psycopg2()psycopg2
SQLAlchemylogfire.instrument_sqlalchemy()sqlalchemy
PyMongologfire.instrument_pymongo()pymongo
MySQLlogfire.instrument_mysql()mysql
SQLite3logfire.instrument_sqlite3()sqlite3
Redislogfire.instrument_redis()redis
Snowflakelogfire.instrument_snowflake()no extra (snowflake-connector-python)

AI/LLM Frameworks

PydanticAI, OpenAI, and Anthropic need no Logfire extra — install the library itself (uv add pydantic-ai / uv add openai / uv add anthropic); Logfire's own AI extras are litellm, dspy, and google-genai.

FrameworkInstrumentorRequirement
PydanticAIlogfire.instrument_pydantic_ai()pydantic-ai installed (no extra)
OpenAIlogfire.instrument_openai()openai installed (no extra)
OpenAI Agents SDKlogfire.instrument_openai_agents()openai-agents installed; imports as agents (no extra)
Anthropiclogfire.instrument_anthropic()anthropic installed (no extra)
Claude Agent SDKlogfire.instrument_claude_agent_sdk()claude_agent_sdk installed (no extra)
LiteLLMlogfire.instrument_litellm()litellm extra
DSPylogfire.instrument_dspy()dspy extra
Google GenAIlogfire.instrument_google_genai()google-genai extra
import logfire

logfire.configure()
logfire.instrument_pydantic_ai()  # captures agent runs, tool calls, LLM request/response
# or:
logfire.instrument_openai()       # captures chat completions, embeddings, token counts
logfire.instrument_anthropic()    # captures messages, token usage

For PydanticAI, each agent run becomes a parent span containing child spans for every tool call and LLM request. See the main skill's Agent Frameworks table for coverage depth across other frameworks (LangChain, CrewAI, AutoGen, ...).

Task Queues

FrameworkInstrumentorExtra
Celerylogfire.instrument_celery()celery

Other

FeatureInstrumentorRequirement
System Metricslogfire.instrument_system_metrics()system-metrics extra
Pydantic model validationlogfire.instrument_pydantic()no extra (distinct from instrument_pydantic_ai() above)
AWS Lambdahandler wrapperaws-lambda extra
SurrealDBlogfire.instrument_surrealdb()no extra
MCP (client and server)logfire.instrument_mcp()no extra
print() redirectionlogfire.instrument_print()no extra

gateway, datasets, and variables are extras too, but for separate product features, not app instrumentation: the AI Gateway proxy, the evals SDK (see the logfire-evals skill), and managed feature flags respectively.

Gunicorn Configuration

# gunicorn.conf.py
import logfire


def post_fork(server, worker):
    logfire.configure()


def post_worker_init(worker):
    logfire.instrument_flask(worker.wsgi)

This example is specific to Flask: configure Logfire in post_fork, then instrument the loaded Flask application in post_worker_init. This preserves Gunicorn's application-loading lifecycle when preload mode is disabled and installs instrumentation in each worker when it is enabled. Other frameworks have different call signatures and placement requirements; follow their row in the table above and their integration documentation rather than mechanically substituting another instrument_*() call here.

Referenced from SKILL.md