Skip to content

Instantly share code, notes, and snippets.

View RNFS's full-sized avatar
🎯
Focusing

Radwan Faris RNFS

🎯
Focusing
  • freelancer
  • Cairo
View GitHub Profile
@RNFS
RNFS / logging_context.py
Created April 16, 2026 12:25
Clean up Python logging with contextvars (Distributed Tracing without passing metadata
"""
Clean Logging with contextvars and pythonjsonlogger
This example demonstrates how to use the built-in contextvars module
to inject metadata (like session_id) into every log message within a
block of code, without passing that metadata through function signatures.
pip install python-json-logger
"""
import uuid