Real-time logging handler for Observo platform
Project description
Observo Handler
Real-time Python logging handler for Observo centralized logging platform.
Features
- 🚀 Real-time logging - Logs sent instantly to Observo
- 🔍 Request tracing - Automatic request_id for all logs
- 👤 User tracking - Automatic user_id for authenticated users
- 📦 Batching - Efficient batch sending to reduce network overhead
- 🛡️ Fail-safe - Won't crash your app if Observo is unavailable
- 🧵 Thread-safe - Background workers handle async sending
Installation
pip install observo-handler
# Or install from source
pip install git+https://github.com/yourusername/observo-handler.git
# Or install locally
pip install /path/to/observo-handler
Quick Start
1. Add to Django settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'observo': {
'class': 'observo_handler.ObservoHandler',
'level': 'INFO',
'project_id': 'your-project-id-here',
'api_key': 'your-api-key-here',
'observo_url': 'https://observo.yourdomain.com/api/v1/ingest/',
'batch_size': 10,
'flush_interval': 5,
},
},
'root': {
'handlers': ['console', 'observo'],
'level': 'INFO',
},
'loggers': {
'django': {
'handlers': ['console', 'observo'],
'level': 'INFO',
'propagate': False,
},
},
}
2. Add Middleware (Optional - for request tracing)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'observo_handler.middleware.RequestIDMiddleware', # Add this
# ... rest of middleware
]
3. Use in Your Code
import logging
logger = logging.getLogger(__name__)
def my_view(request):
logger.info('User accessed view')
try:
# Your code
result = do_something()
logger.debug('Operation successful', extra={'extra_data': {'result': result}})
except Exception as e:
logger.error('Operation failed', exc_info=True)
Configuration
Handler Parameters
project_id(required): Your Observo project IDapi_key(required): Your Observo API keyobservo_url(required): Observo API endpoint URLbatch_size(optional): Number of logs to batch before sending (default: 10)flush_interval(optional): Seconds between automatic flushes (default: 5)level(optional): Minimum log level to capture (default: NOTSET)
Getting Credentials
- Login to your Observo dashboard
- Create or select a project
- Copy the Project ID and API Key from project settings
Advanced Usage
Custom Metadata
Add custom metadata to logs:
logger.info(
'User performed action',
extra={
'extra_data': {
'action': 'purchase',
'amount': 99.99,
'currency': 'USD'
}
}
)
Manual Flushing
import logging
# Get the Observo handler
for handler in logging.getLogger().handlers:
if isinstance(handler, ObservoHandler):
handler.flush() # Force send remaining logs
How It Works
Your Django App
↓
Logger.info("message")
↓
ObservoHandler.emit()
↓
Background Queue (thread-safe)
↓
Batch Worker (batches logs)
↓
HTTP POST to Observo API
↓
Observo Dashboard
Comparison: Handler vs File Shipper
File Shipper (existing)
App → Log File → Shipper reads → Observo
(5 sec delay)
Handler (new)
App → ObservoHandler → Observo (instant)
Requirements
- Python >= 3.8
- Django >= 3.2
- requests >= 2.25.0
License
MIT License
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
observo_handler-1.0.0.tar.gz
(6.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file observo_handler-1.0.0.tar.gz.
File metadata
- Download URL: observo_handler-1.0.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4b1be4b163885d9295b4fd9cf51e4264f4dec8b46f5105a8b2dddf2fb4d00d6
|
|
| MD5 |
497cd7654f624f8586f869de0f881765
|
|
| BLAKE2b-256 |
c146bc982c76e800db6ce667d74f70f6316a120f0297ebd1870bb8561adf406a
|
File details
Details for the file observo_handler-1.0.0-py3-none-any.whl.
File metadata
- Download URL: observo_handler-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90119aec3918580d3bd638893215bfdb233a1b24cabde43e2b4ad45eb4457d64
|
|
| MD5 |
ec09a9341de0123f4a5c5e1589421f6c
|
|
| BLAKE2b-256 |
3444a2bcc79b87f6f1a22ddc99e77b7d39c511f58e6cce031699ba46a9d06547
|