python-observability

Implement structured logging, Prometheus metrics, and OpenTelemetry tracing in Python applications.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill python-observability-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-observability
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/python-observability
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill python-observability-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires structlog, prometheus_client, opentelemetry-sdk, opentelemetry-exporter-otlp-proto-grpc, httpx, fastapi.

What problem does it solve? Production Python applications often lack the instrumentation needed to answer what broke, where, and why without redeploying code. This Skill provides patterns for structured logging, metrics collection, and distributed tracing so you can diagnose production issues from logs and dashboards alone. ## Core Features & Use Cases - Structured Logging: Configure structlog for JSON output with consistent fields, semantic log levels, and correlation ID propagation across services. - Metrics Collection: Track the four golden signals (latency, traffic, errors, saturation) with Prometheus counters, histograms, and gauges while keeping label cardinality bounded. - Distributed Tracing: Set up OpenTelemetry spans with OTLP export to trace requests across service boundaries. - Use Case: A FastAPI service intermittently fails in production. Add correlation ID middleware, instrument endpoints with request metrics, and trace downstream calls to pinpoint the failing dependency from a single request ID. ## Quick Start Add structured logging with correlation IDs and Prometheus request metrics to my FastAPI application.

Frequently Asked Questions about python-observability

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up structured logging in Python with structlog?

Configure structlog with a processor chain including TimeStamper, add_log_level, and JSONRenderer, then call structlog.get_logger() to emit JSON logs. Add structlog.contextvars.merge_contextvars to automatically include correlation IDs in every entry.

How to add Prometheus metrics to a Python API?

Define Counter, Histogram, and Gauge metrics from prometheus_client for request count, latency, and resource usage, then increment them in a decorator or middleware around each endpoint. Use bounded label values like method, endpoint, and status.

How do I propagate correlation IDs across Python microservices?

Store the ID in a ContextVar, set it in middleware from the incoming X-Correlation-ID header or a new UUID, and bind it via structlog.contextvars. Pass the header explicitly on outbound httpx requests to downstream services.

Why should I avoid high-cardinality labels in Prometheus metrics?

Unbounded label values like user IDs create a new time series per value, exploding storage and query costs. Use bounded labels such as endpoint or user tier, and put high-cardinality identifiers in logs instead.

Does OpenTelemetry tracing work with async Python applications?

Yes, OpenTelemetry supports async Python through tracer.start_as_current_span context managers that work in async functions. Configure a TracerProvider with BatchSpanProcessor and an OTLP exporter to send spans to your backend.