observability
2
总安装量
2
周安装量
#75317
全站排名
安装命令
npx skills add https://github.com/jiatastic/open-python-skills --skill observability
Agent 安装分布
claude-code
2
github-copilot
1
Skill 文档
observability
Structured observability patterns for Python APIs using Logfire and OpenTelemetry.
Overview
Use Logfire for fast setup and OpenTelemetry for vendor-neutral exports. Always set service metadata, instrument key frameworks (FastAPI/httpx), and control sampling.
When to Use
- Tracing API requests and dependencies
- Capturing structured logs with context
- Exporting telemetry to OTLP collectors
Quick Start
uv pip install logfire
import logfire
from fastapi import FastAPI
app = FastAPI()
logfire.configure(service_name="backend")
logfire.instrument_fastapi(app)
logfire.instrument_httpx()
Core Patterns
- Service metadata: set
service_nameand environment. - Automatic instrumentation: FastAPI + httpx for request spans.
- Structured logs: include request IDs and user context.
- Sampling: reduce volume for high-traffic services.
- OTLP exports: keep backends swappable.
OpenTelemetry Export Example
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
resource = Resource(attributes={"service.name": "service"})
trace.set_tracer_provider(TracerProvider(resource=resource))
tracer = trace.get_tracer(__name__)
exporter = OTLPSpanExporter()
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(exporter))
with tracer.start_as_current_span("healthcheck"):
pass
Troubleshooting
- Missing service name: spans hard to find in UI
- High-cardinality attributes: explode storage
- No spans: instrumentation called too late