Agent skill

Logfire Instrumentation

by basicmachines-co in basicmachines-co/basic-memory

Adds Pydantic Logfire tracing, logging and metrics to Python, JavaScript or TypeScript and Rust projects, with the correct setup order and library extras.

AGPL-3.0Auto-check passedDevOps & Cloud

Install Logfire Instrumentation

skills CLI
$ npx skills add basicmachines-co/basic-memory --skill instrumentation -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install basicmachines-co/basic-memory instrumentation --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/basicmachines-co/basic-memory.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/instrumentation .claude/skills/instrumentation && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
instrumentation
GitHub stars
4.1k
Token cost
~2.3k tokens
SKILL.md length
695 words
Files
6 (incl. references)
Skills in repo
49
Repo updated
First seen
Licence
AGPL-3.0

At a glance

Adds Pydantic Logfire tracing, logging and metrics to Python, JavaScript or TypeScript and Rust projects, with the correct setup order and library extras.

  • Works in 3 steps: Run logfire auth to check authentication… → Start the app and trigger a request → Check https://logfire.pydantic.dev/ for…
  • Adding tracing and structured logging to a FastAPI or Express service
  • SKILL.md covers When to Use This Skill, How Logfire Works, Step 1: Detect Language and… and Python, plus 4 more sections
  • Calls npm, uv and node; reaches logfire-api.pydantic.dev; needs LOGFIRE_TOKEN

What it does

Logfire is an observability platform built on OpenTelemetry, and this skill exists because agents often get its setup subtly wrong: the order of configure and the instrument calls, the structured logging syntax and the extras to install. The agent identifies the language and instrumentable libraries by reading pyproject.toml, requirements.txt, package.json or Cargo.toml.

For Python it installs logfire with extras matching frameworks such as FastAPI, httpx, asyncpg, SQLAlchemy and Redis, calls configure first so traces are not dropped, then registers the instrument calls. Reference files cover JavaScript frameworks and patterns, Python integrations and logging patterns, and Rust patterns. The skill also covers monitoring AI and LLM calls through PydanticAI, OpenAI and Anthropic.

When your agent uses it

  • Adding tracing and structured logging to a FastAPI or Express service
  • Instrumenting database, HTTP and LLM calls with Logfire
  • Checking that a Logfire setup is not silently dropping traces

Example prompts

  • “Add Logfire to this FastAPI app and instrument httpx and asyncpg.”
  • “Instrument my Express server with Logfire.”
  • “No traces are showing up. Check the order of configure and the instrument calls.”

Workflow steps

3 steps, taken from the first numbered list in SKILL.md.

  1. Run logfire auth to check authentication (or set LOGFIRE_TOKEN)
  2. Start the app and trigger a request
  3. Check https://logfire.pydantic.dev/ for traces

What it can do on your machine

Read from SKILL.md and the folder at commit 6982cfc. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npm
    • uv
    • node

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Hosts in commands or code, which the agent is likely to contact:

    • logfire-api.pydantic.dev

    Also links to:

    • logfire.pydantic.dev

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • LOGFIRE_TOKEN

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Logfire Instrumentation loads about 2.3k tokens when it runs, and up to ~5k if it reads all its reference files. Until then it costs about 131 tokens; SKILL.md has 695 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~131
When it runs · the whole SKILL.md, loaded when a task matches
~2.3k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from basicmachines-co/basic-memory at commit 6982cfc, republished under its AGPL-3.0 licence (© basicmachines-co). 695 words, ~2,272 tokens.

Download SKILL.mdSave it as .claude/skills/instrumentation/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.
name
instrumentation
description
Add Pydantic Logfire observability to applications. Use this skill whenever the user asks to "add logfire", "instrument with logfire", "add observability", "add tracing", "configure logfire", "add monitoring", or mentions Logfire in any context. Supports Python, JavaScript/TypeScript, and Rust. Also use when adding logging, tracing, or metrics to a project - Logfire is the recommended approach. Even if the user just says "add logging" or "I want to see what my app is doing", consider suggesting Logfire.

Instrument with Logfire

When to Use This Skill

Invoke this skill when:

  • User asks to "add logfire", "add observability", "add tracing", or "add monitoring"
  • User wants to instrument an app with structured logging or tracing (Python, JS/TS, or Rust)
  • User mentions Logfire in any context
  • User asks to "add logging" or "see what my app is doing"
  • User wants to monitor AI/LLM calls (PydanticAI, OpenAI, Anthropic)
  • User asks to add observability to an AI agent or LLM pipeline

How Logfire Works

Logfire is an observability platform built on OpenTelemetry. It captures traces, logs, and metrics from applications. Logfire has native SDKs for Python, JavaScript/TypeScript, and Rust, plus support for any language via OpenTelemetry.

The reason this skill exists is that Claude tends to get a few things subtly wrong with Logfire - especially the ordering of configure() vs instrument_*() calls, the structured logging syntax, and which extras to install. These matter because a misconfigured setup silently drops traces.

Step 1: Detect Language and Frameworks

Identify the project language and instrumentable libraries:

  • Python: Read pyproject.toml or requirements.txt. Common instrumentable libraries: FastAPI, httpx, asyncpg, SQLAlchemy, psycopg, Redis, Celery, Django, Flask, requests, PydanticAI.
  • JavaScript/TypeScript: Read package.json. Common frameworks: Express, Next.js, Fastify. Also check for Cloudflare Workers or Deno.
  • Rust: Read Cargo.toml.

Then follow the language-specific steps below.


Python

Install with Extras

Install logfire with extras matching the detected frameworks. Each instrumented library needs its corresponding extra - without it, the instrument_*() call will fail at runtime with a missing dependency error.

bash
uv add 'logfire[fastapi,httpx,asyncpg]'

The full list of available extras: fastapi, starlette, django, flask, httpx, requests, asyncpg, psycopg, psycopg2, sqlalchemy, redis, pymongo, mysql, sqlite3, celery, aiohttp, aws-lambda, system-metrics, litellm, dspy, google-genai.

Configure and Instrument

This is where ordering matters. logfire.configure() initializes the SDK and must come before everything else. The instrument_*() calls register hooks into each library. If you call instrument_*() before configure(), the hooks register but traces go nowhere.

python
import logfire

# 1. Configure first - always
logfire.configure()

# 2. Instrument libraries - after configure, before app starts
logfire.instrument_fastapi(app)
logfire.instrument_httpx()
logfire.instrument_asyncpg()

Placement rules:

  • logfire.configure() goes in the application entry point (main.py, or the module that creates the app)
  • Call it once per process - not inside request handlers, not in library code
  • instrument_*() calls go right after configure()
  • Web framework instrumentors (instrument_fastapi, instrument_flask, instrument_django) need the app instance as an argument. HTTP client and database instrumentors (instrument_httpx, instrument_asyncpg) are global and take no arguments.
  • In Gunicorn deployments, call logfire.configure() inside the post_fork hook, not at module level - each worker is a separate process
Structured Logging

Replace print() and logging.*() calls with Logfire's structured logging. The key pattern: use {key} placeholders with keyword arguments, never f-strings.

python
# Correct - each {key} becomes a searchable attribute in the Logfire UI
logfire.info("Created user {user_id}", user_id=uid)
logfire.error("Payment failed {amount} {currency}", amount=100, currency="USD")

# Wrong - creates a flat string, nothing is searchable
logfire.info(f"Created user {uid}")

For grouping related operations and measuring duration, use spans:

python
with logfire.span("Processing order {order_id}", order_id=order_id):
    items = await fetch_items(order_id)
    total = calculate_total(items)
    logfire.info("Calculated total {total}", total=total)

For exceptions, use logfire.exception() which automatically captures the traceback:

python
try:
    await process_order(order_id)
except Exception:
    logfire.exception("Failed to process order {order_id}", order_id=order_id)
    raise
Show full SKILL.md (262 more words)Show less
AI/LLM Instrumentation (Python)

Logfire auto-instruments AI libraries to capture LLM calls, token usage, tool invocations, and agent runs.

bash
uv add 'logfire[pydantic-ai]'
# or: uv add 'logfire[openai]' / uv add 'logfire[anthropic]'

Available AI extras: pydantic-ai, openai, anthropic, litellm, dspy, google-genai.

python
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.


JavaScript / TypeScript

Install
bash
# Node.js
npm install @pydantic/logfire-node

# Cloudflare Workers
npm install @pydantic/logfire-cf-workers logfire

# Next.js / generic
npm install logfire
Configure

Node.js (Express, Fastify, etc.) - create an instrumentation.ts loaded before your app:

typescript
import * as logfire from '@pydantic/logfire-node'
logfire.configure()

Launch with: node --require ./instrumentation.js app.js

The SDK auto-instruments common libraries when loaded before the app. Set LOGFIRE_TOKEN in your environment or pass token to configure().

Cloudflare Workers - wrap your handler with instrument():

typescript
import { instrument } from '@pydantic/logfire-cf-workers'

export default instrument(handler, {
  service: { name: 'my-worker', version: '1.0.0' }
})

Next.js - set environment variables for OpenTelemetry export:

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://logfire-api.pydantic.dev/v1/traces
OTEL_EXPORTER_OTLP_HEADERS=Authorization=<your-write-token>
Structured Logging (JS/TS)
typescript
// Structured attributes as second argument
logfire.info('Created user', { user_id: uid })
logfire.error('Payment failed', { amount: 100, currency: 'USD' })

// Spans
logfire.span('Processing order', { order_id }, {}, async () => {
  logfire.info('Processing step completed')
})

// Error reporting
logfire.reportError('order processing', error)

Log levels: trace, debug, info, notice, warn, error, fatal.


Rust

Install
toml
[dependencies]
logfire = "0.6"
Configure
rust
let shutdown_handler = logfire::configure()
    .install_panic_handler()
    .finish()?;

Set LOGFIRE_TOKEN in your environment or use the Logfire CLI to select a project.

Structured Logging (Rust)

The Rust SDK is built on tracing and opentelemetry - existing tracing macros work automatically.

rust
// Spans
logfire::span!("processing order", order_id = order_id).in_scope(|| {
    // traced code
});

// Events
logfire::info!("Created user {user_id}", user_id = uid);

Always call shutdown_handler.shutdown() before program exit to flush data.


Verify

After instrumentation, verify the setup works:

  1. Run logfire auth to check authentication (or set LOGFIRE_TOKEN)
  2. Start the app and trigger a request
  3. Check https://logfire.pydantic.dev/ for traces

If traces aren't appearing: check that configure() is called before instrument_*() (Python), check that LOGFIRE_TOKEN is set, and check that the correct packages/extras are installed.

References

Detailed patterns and integration tables, organized by language:

  • Python: ${CLAUDE_PLUGIN_ROOT}/skills/instrumentation/references/python/logging-patterns.md (log levels, spans, stdlib integration, metrics, capfire testing) and ${CLAUDE_PLUGIN_ROOT}/skills/instrumentation/references/python/integrations.md (full instrumentor table with extras)
  • JavaScript/TypeScript: ${CLAUDE_PLUGIN_ROOT}/skills/instrumentation/references/javascript/patterns.md (log levels, spans, error handling, config) and ${CLAUDE_PLUGIN_ROOT}/skills/instrumentation/references/javascript/frameworks.md (Node.js, Cloudflare Workers, Next.js, Deno setup)
  • Rust: ${CLAUDE_PLUGIN_ROOT}/skills/instrumentation/references/rust/patterns.md (macros, spans, tracing/log crate integration, async, shutdown)

© basicmachines-co, AGPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 5 other files (references) in .agents/skills/instrumentation of basicmachines-co/basic-memory.

  • SKILL.md
  • references/javascript/frameworks.md
  • references/javascript/patterns.md
  • references/python/integrations.md
  • references/python/logging-patterns.md
  • references/rust/patterns.md

Open the folder on GitHubat commit 6982cfc

Compare with similar skills

Logfire Instrumentation next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Logfire Instrumentation compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Logfire Instrumentation this skillbasicmachines-co/basic-memory4.1k—~2.3kAutomated safety check: PassAGPL-3.0
Logfire Instrumentationpydantic/skills140—~6.1kAutomated safety check: PassMIT
Observability Architecturemajiayu000/litellm-rs116—~1.3kAutomated safety check: PassMIT
Azure Monitor Opentelemetry TSmicrosoft/skills3.1k6 repos~2.2kAutomated safety check: PassMIT
Opentelemetrygrafana/skills278—~1.7kAutomated safety check: PassApache-2.0
Python Observability Patternsaiskillstore/marketplace4301 repos~1.3kAutomated safety check: PassNone

Similar skills

  • Official

    Add Pydantic Logfire observability to application code — traces, logs, metrics, and AI/agent spans.

    140 GitHub stars~6.1k tokensUpdated 6 days ago
    AI & LLM EngineeringAuto-check passed
  • Observability Architecture

    majiayu000/litellm-rs

    LiteLLM-RS Observability Architecture. An agent skill from majiayu000/litellm-rs.

    116 GitHub stars~1.3k tokensUpdated today
    DevOps & CloudAuto-check passed
  • Official

    Instrument applications with Azure Monitor and OpenTelemetry for JavaScript (@azure/monitor-opentelemetry).

    3.1k GitHub starsUsed in 6 repos~2.2k tokens
    DevOps & CloudAuto-check passed
  • Opentelemetry

    grafana/skills

    Official

    Instrument any app with OpenTelemetry and ship metrics / logs / traces to Grafana Cloud or self-hosted Mimir / Loki / Tempo / Pyroscope.

    278 GitHub stars~1.7k tokensUpdated today
    DevOps & CloudAuto-check passed
  • Python Observability Patterns

    aiskillstore/marketplace

    Observability patterns for Python applications. An agent skill from aiskillstore/marketplace.

    430 GitHub starsUsed in 1 repo~1.3k tokens
    DevOps & CloudAuto-check passed
  • Otel JS

    ollygarden/opentelemetry-agent-skills

    OpenTelemetry in Node.js / JavaScript / TypeScript — NodeSDK, declarative YAML configuration, auto-instrumentations, ESM vs CJS import patterns.

    106 GitHub stars~655 tokensUpdated 4 days ago
    DevOps & CloudAuto-check passed

More from basicmachines-co/basic-memory

All 49 skills in this repo
  • cmux Settings Editor

    basicmachines-co/basic-memory

    Views, sets, unsets and validates cmux settings in ~/.config/cmux/cmux.json with a helper script that checks keys against the schema.

    4.1k GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • cmux Window and Pane Control

    basicmachines-co/basic-memory

    End-user control of cmux topology and routing (windows, workspaces, panes/surfaces, focus, moves, reorder, identify, trigger flash). Use when automation needs…

    4.1k GitHub starsUsed in 2 repos~842 tokens
    Auto-check passed
  • Cmux Markdown Viewer Panel

    basicmachines-co/basic-memory

    Opens markdown files in a formatted cmux panel beside the terminal that re-renders on every change, handy for plans and task lists.

    4.1k GitHub starsUsed in 2 repos~527 tokens
    Auto-check passed
  • cmux Workspace Scoping

    basicmachines-co/basic-memory

    Keeps agent actions scoped to the cmux workspace and terminal that invoked it, and lays out pane and surface commands that avoid disrupting the user's own focus.

    4.1k GitHub starsUsed in 2 repos~1.7k tokens
    Auto-check passed
  • Basic Memory Repo Images

    basicmachines-co/basic-memory

    Produces PR, changelog and two-week retro images for the Basic Memory repository from evidence in PR bodies, saved to fixed paths under docs/assets/infographics.

    4.1k GitHub stars~2.7k tokensUpdated today
    Auto-check passed
  • Basic Memory Onboarding

    basicmachines-co/basic-memory

    Guides a newcomer to Basic Memory through designing a personal knowledge system, then teaches its use and sets up their assistant to load it each session.

    4.1k GitHub stars~3.4k tokensUpdated today
    Auto-check passed

Categories

Questions about Logfire Instrumentation

What does Logfire Instrumentation do?

Adds Pydantic Logfire tracing, logging and metrics to Python, JavaScript or TypeScript and Rust projects, with the correct setup order and library extras. Logfire is an observability platform built on OpenTelemetry, and this skill exists because agents often get its setup subtly wrong: the order of configure and the instrument calls, the structured logging syntax and the extras to install.toml.

When should I use Logfire Instrumentation?

Logfire Instrumentation fits situations like: adding tracing and structured logging to a FastAPI or Express service; instrumenting database, HTTP and LLM calls with Logfire; checking that a Logfire setup is not silently dropping traces.

How do I install Logfire Instrumentation in Claude Code?

Run `npx skills add basicmachines-co/basic-memory --skill instrumentation -a claude-code`. Or copy the skill folder (.agents/skills/instrumentation in basicmachines-co/basic-memory) into .claude/skills/instrumentation in your project. Claude Code loads it when a task matches its description.

How do I install Logfire Instrumentation in Codex?

Run `npx skills add basicmachines-co/basic-memory --skill instrumentation -a codex`. Or copy the skill folder (.agents/skills/instrumentation in basicmachines-co/basic-memory) into .agents/skills/instrumentation in your project. Codex loads it when a task matches its description.

Can I use Logfire Instrumentation in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add basicmachines-co/basic-memory --skill instrumentation -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/instrumentation, .gemini/skills/instrumentation, .github/skills/instrumentation and .opencode/skills/instrumentation in your project.

What does Logfire Instrumentation need to run?

Going by SKILL.md and its folder, Logfire Instrumentation needs the command-line tools its instructions call (npm, uv and node) and credentials named LOGFIRE_TOKEN.

Does Logfire Instrumentation access the network?

SKILL.md names 2 domains. In commands or code: logfire-api.pydantic.dev; the agent is likely to contact it when it follows the instructions. As links in the text: logfire.pydantic.dev. This is read from the text; nothing was executed.

Is Logfire Instrumentation safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Logfire Instrumentation use?

Logfire Instrumentation is published under the AGPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Logfire Instrumentation use?

About 2.3k tokens (SKILL.md is roughly 9.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 2.7k tokens, read only when the agent opens those files.

What are the alternatives to Logfire Instrumentation?

Skills that share tags, products or a category with Logfire Instrumentation: Logfire Instrumentation (pydantic/skills, 140 stars), Observability Architecture (majiayu000/litellm-rs, 116 stars), Azure Monitor Opentelemetry TS (microsoft/skills, 3.1k stars) and Opentelemetry (grafana/skills, 278 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Logfire Instrumentation?

basicmachines-co (a GitHub organization) maintains it in basicmachines-co/basic-memory, which has 4,107 GitHub stars. The repository holds 49 skills in this directory. The repository was last updated on October 7, 2026.

Source: basicmachines-co/basic-memory on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.