Observability¶
Monitoring, logging, and tracing for production applications.
Overview¶
Observability helps you understand what's happening inside your application:
- Logging — Structured logs with colorlog
- Tracing — Distributed tracing with Logfire (OpenTelemetry)
- Metrics — Performance data via OpenTelemetry
Architecture¶
┌─────────────────────────────────────────────────────────┐
│ Application │
├─────────────┬─────────────────────┬────────────────────┤
│ Logging │ OpenTelemetry SDK │ Instrumentation │
│ (colorlog) │ (Logfire) │ (auto-detected) │
└──────┬──────┴──────────┬──────────┴─────────┬──────────┘
│ │ │
▼ ▼ ▼
Console Logfire Automatic
Output Platform Tracing
Topics¶
-
Logging
Console logging with colors and log levels.
-
Logfire (OpenTelemetry)
Distributed tracing with Pydantic's Logfire platform.
-
Instrumented Libraries
Auto-instrumented libraries for tracing.
-
Sensitive Data Scrubbing
Protecting secrets in traces and logs.
Quick Start¶
Enable Logging¶
Set the log level:
Enable Logfire¶
- Sign up at logfire.pydantic.dev
- Get your project token
- Configure environment:
Bootstrap Sequence¶
Observability is configured during application startup:
# src/core/configs/infrastructure.py
def configure_infrastructure(service_name: str) -> None:
load_dotenv(override=False)
configure_logging() # Set up logging first
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.configs.django")
django.setup()
configure_logfire( # Then set up tracing
service_name=service_name,
environment=application_settings.environment,
version=application_settings.version,
)
Service Names¶
Each entry point has a unique service name for identification:
| Entry Point | Service Name |
|---|---|
| HTTP API | http |
| Telegram Bot | bot |
| Celery Worker | celery-worker |
| Celery Beat | celery-beat |
Related Topics¶
- Production Configuration — Production settings
- Docker Compose — Container configuration