Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问许可证需确认审计通过

instrumentationinstrumentation 搜索

Agent Skill

instrumentation 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

8,380

周安装

339

GitHub Stars

45

下载量

2,631
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:instrumentation(instrumentation 搜索)
来源仓库:https://github.com/pydantic/skills
仓库路径:skills/instrumentation
安装命令:
npx skills add https://github.com/pydantic/skills --skill instrumentation
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/pydantic/skills --skill instrumentation

简介

instrumentation 用于查找、检索和筛选相关信息,适合快速定位候选结果。

  • 适用于需要根据关键词或任务场景从来源线索中筛选信息的场景。
  • 通过关键词、任务场景或来源线索进行信息检索和筛选。
  • 安装前需确认权限范围、维护状态及是否触发联网或文件读写操作。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

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.

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.

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.

# 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:

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:

try:
    await process_order(order_id)
except Exception:
    logfire.exception("Failed to process order {order_id}", order_id=order_id)
    raise

AI/LLM Instrumentation (Python)

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

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.

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

# 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:

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():

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)

// 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

[dependencies]
logfire = "0.6"

Configure

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.

// 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)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.73%
按下载量换算861

Claude

31.76%
按下载量换算836

Cursor

19.66%
按下载量换算517

Gemini CLI

8.5%
按下载量换算224

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills