python-observability

Instrument Python applications with structured logging, Prometheus metrics, and OpenTelemetry tracing.

Updated Mar 3, 2026
One-click install
npx skills add https://github.com/jacexh/skills --skill python-observability-jacexh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-observability
Source: https://github.com/jacexh/skills/tree/main/skills/python-observability
Command: npx skills add https://github.com/jacexh/skills --skill python-observability-jacexh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provide engineers with practical patterns to answer what happened, where it happened, and why in production by adding structured logs, request-level metrics, and distributed traces so incidents can be diagnosed without redeploying code.

Core Features & Use Cases

  • Structured JSON logging for machine-readable, queryable logs with consistent fields and semantic log levels.
  • Metrics instrumentation using Prometheus primitives to track latency, traffic, errors, and saturation with bounded label cardinality.
  • Distributed tracing via OpenTelemetry with OTLP export and span propagation across service boundaries.
  • Correlation ID propagation via contextvars and middleware to link logs, metrics, and traces end-to-end.
  • Reusable patterns such as timing context managers, decorators for request tracking, and guidance for testing observability pipelines.

Quick Start

Instrument my FastAPI service with structlog JSON logging, add Prometheus metrics for HTTP requests and errors, and configure OpenTelemetry tracing with middleware and an OTLP exporter.

Frequently Asked Questions about python-observability

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

FAQPage Schema
How do I instrument a FastAPI application with structured logging and Prometheus metrics?

To instrument FastAPI applications, apply structlog for structured JSON logging and Prometheus primitives to track HTTP request latency, traffic, and errors with bounded label cardinality. This setup ensures machine-readable logs and request-level metrics for production observability.

How does correlation ID propagation link logs and traces across microservices?

Correlation ID propagation uses contextvars and middleware to link logs, metrics, and distributed traces end-to-end across service boundaries. This mechanism passes unique identifiers through request flows and background jobs, ensuring traceability across microservices.

What is the best way to export OpenTelemetry spans from Python backend services?

Exporting OpenTelemetry spans from Python backend services is best achieved by configuring OTLP-compatible trace export with middleware. This approach propagates spans across request flows and background jobs, enabling distributed tracing to diagnose production incidents without redeploying code.

Can I add observability to Python microservices without redeploying code?

Adding observability to Python microservices requires applying instrumentation patterns like timing context managers and request tracking decorators to your codebase. These reusable patterns add structured logs, metrics, and traces so incidents can be diagnosed without needing to recompile or redeploy.

Does this observability instrumentation work with Flask applications?

Yes, the observability instrumentation applies to Flask applications alongside FastAPI and backend services. It adds structured logging, Prometheus request metrics, and OpenTelemetry spans to meet JSON structured logs and OTLP-compatible trace export requirements.

Why should I bound metric label cardinality when tracking Prometheus request metrics?

Bounding metric label cardinality is required when tracking Prometheus request metrics to prevent uncontrolled growth of time series data. The instrumentation uses bounded label cardinality to safely track latency, traffic, errors, and saturation without overwhelming storage.