python-observability-patterns

Solid

Observability patterns for Python applications. Triggers on: logging, metrics, tracing, opentelemetry, prometheus, observability, monitoring, structlog, correlation id.

DevOps & Infrastructure 335 stars 29 forks Updated today

Install

View on GitHub

Quality Score: 85/100

Stars 20%
84
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
0
Description 5%
100

Skill Content

# Python Observability Patterns Logging, metrics, and tracing for production applications. ## Structured Logging with structlog ```python import structlog # Configure structlog structlog.configure( processors=[ structlog.contextvars.merge_contextvars, structlog.processors.add_log_level, structlog.processors.TimeStamper(fmt="iso"), structlog.processors.JSONRenderer(), ], wrapper_class=structlog.make_filtering_bound_logger(logging.INFO), context_class=dict, logger_factory=structlog.PrintLoggerFactory(), ) logger = structlog.get_logger() # Usage logger.info("user_created", user_id=123, email="test@example.com") # Output: {"event": "user_created", "user_id": 123, "email": "test@example.com", "level": "info", "timestamp": "2024-01-15T10:00:00Z"} ``` ## Request Context Propagation ```python import structlog from contextvars import ContextVar from uuid import uuid4 request_id_var: ContextVar[str] = ContextVar("request_id", default="") def bind_request_context(request_id: str | None = None): """Bind request ID to logging context.""" rid = request_id or str(uuid4()) request_id_var.set(rid) structlog.contextvars.bind_contextvars(request_id=rid) return rid # FastAPI middleware @app.middleware("http") async def request_context_middleware(request, call_next): request_id = request.headers.get("X-Request-ID") or str(uuid4()) bind_request_context(request_id) response = await call_next(request) ...

Details

Author
aiskillstore
Repository
aiskillstore/marketplace
Created
5 months ago
Last Updated
today
Language
Python
License
None

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category