python-observability
Python observability patterns including structured logging, metrics, and distributed tracing. Use when adding logging, implementing metrics collection, setting up tracing, or debugging production systems.
By wshobson · 10,219 installs
npx skills add wshobson/agents --skill python-observability
Source repository · Upstream listing
Python Observability
Instrument Python applications with structured logs, metrics, and traces. When something breaks in production, you need to answer "what, where, and why" without deploying new code.
When to Use This Skill
Adding structured logging to applications
Implementing metrics collection with Prometheus
Setting up distributed tracing across services
Propagating correlation IDs through request chains
Debugging production issues
Building observability dashboards
Core Concepts
1. Structured Logging
Emit logs as JSON with consistent fields for production environments. Machine readable logs enable powerful queries and alerts. For local development, consider human readable formats.
2. The Four Golden Signals
Track latency, traffic, errors, and saturation for every service boundary.
3. Correlation IDs
Thread a unique ID through all logs and spans for a single request, enabling end to end tracing.
4. Bounded Cardinality
Keep metric label values bounded. Unbounded labels (like user IDs) explode storage costs.
Quick Start
Fundamental Patterns
Pattern 1: Structured Logging with Structlog
Configure structlog for JSON output with consistent fields.
Pattern 2: Consistent Log Fields
Every log entry should include standard fields for filtering and correlation.
Pattern 3: Semantic Log Levels
Use log levels consistently across the application.
Level Purpose Examples
DEBUG Development diagnostics Variable values, internal state
INFO Request lifecycle, operations Request start/end, job completion
WARNING Recoverable anomalies Retry attempts, fallback used
ERROR Failures needing attention Exceptions, service unavailable
Never log expected behavior at ERROR . A user entering a wrong password is INFO , not ERROR .
Pattern 4: Correlation ID Propagation
Generate a unique ID at ingress and thread it through all operations.
Propagate to outbound requests:
Detailed worked examples and patterns
Detailed sections (starting with Advanced Patterns ) live in references/details.md . Read that file when the navigation summary above is insufficient.
Best Practices Summary
1. Use structured logging JSON logs with consistent fields
2. Propagate correlation IDs Thread through all requests and logs
3. Track the four golden signals Latency, traffic, errors, saturation
4. Bound label cardinality Never use unbounded values as metric labels
5. Log at appropriate levels Don't cry wolf with ERROR
6. Include context User ID, request ID, operation name in logs
7. Use context managers Consistent timing and error handling
8. Separate concerns Observability code shouldn't pollute business logic
9. Test your observability Verify logs and metrics in integration tests
10. Set up alerts Metrics are useless without alerting