python-observability-patterns
SolidObservability patterns for Python applications. Triggers on: logging, metrics, tracing, opentelemetry, prometheus, observability, monitoring, structlog, correlation id.
DevOps & Infrastructure 422 stars
44 forks Updated today
Install
Quality Score: 86/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
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
- 8 months ago
- Last Updated
- today
- Language
- Python
- License
- None
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Listed
python-observability
Python observability patterns including structured logging, metrics, and distributed tracing.
2 Updated 3 days ago
Jartan-LLC DevOps & Infrastructure Listed
observability-logging-metrics-tracing
Add or review logging, metrics, or tracing so production behavior is diagnosable — structured logs, correlation IDs, RED/USE metrics, and OpenTelemetry spans. Use when instrumenting code, debugging a production issue, or wiring monitoring. Triggers on logging, metrics, tracing, observability, instrument, debug production, monitoring.
0 Updated 1 months ago
BenMacDeezy DevOps & Infrastructure Solid
loom-logging-observability
Logging and observability patterns for production systems.
54 Updated today
cosmix