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/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 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

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.0.tar.gz (6.6 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.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

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

Hashes for observo_handler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f4b1be4b163885d9295b4fd9cf51e4264f4dec8b46f5105a8b2dddf2fb4d00d6
MD5 497cd7654f624f8586f869de0f881765
BLAKE2b-256 c146bc982c76e800db6ce667d74f70f6316a120f0297ebd1870bb8561adf406a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for observo_handler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90119aec3918580d3bd638893215bfdb233a1b24cabde43e2b4ad45eb4457d64
MD5 ec09a9341de0123f4a5c5e1589421f6c
BLAKE2b-256 3444a2bcc79b87f6f1a22ddc99e77b7d39c511f58e6cce031699ba46a9d06547

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