python-observability

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

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-observability-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-observability
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/python-observability
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill python-observability-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Production Python applications often lack the visibility 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 quickly. ## Core Features & Use Cases - Structured Logging with structlog: Emit JSON logs with consistent fields, semantic log levels, and correlation IDs threaded through request chains via contextvars and middleware. - Prometheus Metrics: Track the four golden signals (latency, traffic, errors, saturation) with bounded label cardinality to avoid metric explosion. - Distributed Tracing: Set up OpenTelemetry spans with OTLP export to trace requests across services. - Use Case: When a payment endpoint starts failing intermittently in production, use correlation IDs to trace a single request across services, query structured logs for error context, and check latency histograms to pinpoint the slow dependency. ## Quick Start Add structured logging with structlog and a correlation ID middleware 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 merge_contextvars, add_log_level, TimeStamper, and JSONRenderer, then call structlog.get_logger() to emit JSON logs. Initialize the configuration once at application startup with your desired log level.

How to propagate correlation IDs across Python microservices?

Store the correlation ID in a ContextVar and bind it with structlog.contextvars so it appears in every log entry. Accept or generate the ID in middleware via the X-Correlation-ID header, then forward that header on outbound httpx requests to downstream services.

What metrics should I track with Prometheus for a web service?

Track the four golden signals: request latency as a Histogram, traffic as a Counter, errors as a Counter labeled by error type, and saturation as a Gauge such as database connection pool usage. Label metrics by method, endpoint, and status.

Why should I avoid user IDs as Prometheus metric labels?

User IDs have unbounded cardinality, creating millions of time series that explode storage costs and degrade query performance. Use bounded labels like endpoint or user tier instead, and record user IDs in structured logs where high cardinality is safe.

Does OpenTelemetry tracing work with FastAPI and async Python?

Yes, OpenTelemetry supports async Python through tracer.start_as_current_span context managers around awaited operations. Configure a TracerProvider with a BatchSpanProcessor and OTLP exporter, and check the official docs since the API evolves actively.