Skip to main content

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/kennedy-ak/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 ID
  • api_key (required): Your Observo API key
  • observo_url (required): Observo API endpoint URL
  • batch_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

  1. Login to your Observo dashboard
  2. Create or select a project
  3. 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

📧 Email: akogokennedy@gmail.com

📚 Documentation: https://github.com/kennedy-ak/observo-handler

🐛 Issues: https://github.com/kennedy-ak/observo-handler/issues

💬 Discussions: https://github.com/kennedy-ak/observo-handler/discussions

Project details


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.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

observo_handler-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file observo_handler-1.0.1.tar.gz.

File metadata

  • Download URL: observo_handler-1.0.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for observo_handler-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6a2fec66e50df8c9e604ac3a4406a188e43953db72ea19a96a47b8e861376444
MD5 37cce22a72f69600c219219c5e1f6065
BLAKE2b-256 ad2a777a2c7cb2bfee87aaa3b9520fe9805f3ae8bfea241c7a64a5656f9cc9fb

See more details on using hashes here.

File details

Details for the file observo_handler-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for observo_handler-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 764c9206677108b72cd72b2734e8e8b052805ddff5ce06636ed361f801979993
MD5 bb0b84358bfd0feb23a72b4790fb379f
BLAKE2b-256 612830ec181a8d29742e391e535c8549e9723ded70e01a10df6d77503ad236c6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page