A Lightweight, Zero-Configuration Observability Middleware for Python Backends
Project description
Trazelet
A Lightweight, Zero-Configuration Observability Middleware for Python Backends
Seamlessly integrates with FastAPI, Django, and Flask to deliver instant HTTP and API performance insights
Features • Quick Start • Documentation • Purpose • Contributing
🎯 What is Trazelet?
Trazelet is a high-performance, open-source Python plug-and-play middleware library that provides backend developers with instant HTTP and API performance analytics. It delivers immediate visibility into request latency without the complexity or overhead of traditional enterprise APM tools, and integrates seamlessly with Python web frameworks with zero configuration.
The Problem It Solves
Most developers don't know their API is slow until a user complains. Enterprise tools (like New Relic, Datadog) are too expensive or hard to set up for small-to-medium projects. Trazelet fills this gap by being local, private, and lightweight.
Why Trazelet?
- 🚀 Near-Zero Overhead: Non-blocking design with <0.2ms average latency impact
- 🔒 Privacy-First: All data stays on your machine. No cloud, no external services
- 🎯 Zero Configuration: Works out of the box with sensible defaults
- 🔌 Framework Agnostic: Works seamlessly with FastAPI, Django, and Flask
- ⚡ Production-Ready: Thread-safe, battle-tested architecture
- 📊 Built-in Performance Analytics: Actionable HTTP and API performance metrics out of the box
- 💻 Modern TUI Interface: Access real-time and historical analytics through a Rich-powered terminal UI
✨ Features
Core Capabilities
- ✅ Automatic Request Tracking: Captures latency, status codes, and API paths
- ✅ Non-Blocking Architecture: Queue-based buffering ensures zero impact on response times
- ✅ Batch Processing: Configurable batching for high-performance metric storage
- ✅ Thread-Safe: Verified with 100+ concurrent operations
- ✅ Invisible Middleware: Never crashes your application, graceful error handling
- ✅ Local Storage: SQLite (default) or PostgreSQL support
- ✅ Route Normalization: Automatically normalizes dynamic paths (
/user/123→/user/<id>)
Framework Support
- ✅ FastAPI: Clean ASGI middleware integration
- ✅ Django: Standard middleware pattern
- ✅ Flask: Proper request tracking with
gobject
Analytics & TUI Capabilities
- 📊 Real-time Performance Reports: Instant health overviews and detailed metric breakdowns via CLI.
- 📈 Endpoint Health Grading: Automated A/B/C/D grading for API endpoints based on performance.
- 🐢 Anomaly Detection: Quickly pinpoint slowest or most error-prone endpoints.
- 🎨 Rich Command-Line Interface: Interactive terminal output with tables, panels, and color-coding, powered by
Rich. - 📋 Flexible Output Formats: View analytics in human-readable tables, compact views, or machine-parseable JSON.
Core Performance Metrics
- Capture Latency: ~0.12ms average (non-blocking) ensures minimal impact.
- Concurrent Operations: Thread-safe design, verified with 100+ concurrent captures.
- Background Database Writes: Asynchronous processing with zero impact on the request path.
- Minimal Memory Footprint: Efficient queue-based buffering for low resource consumption.
🚀 Quick Start
Installation
# Core installation
pip install trazelet
Basic Usage
FastAPI
from fastapi import FastAPI
from trazelet.integrations.fastapi import FastAPIMiddleware
import trazelet
# Initialize Trazelet (uses SQLite by default)
trazelet.init()
app = FastAPI()
app.add_middleware(FastAPIMiddleware)
@app.get("/")
def read_root():
return {"message": "Hello World"}
Django
# settings.py
MIDDLEWARE = [
# ... other middleware ...
"trazelet.integrations.django.DjangoMiddleware",
]
# Initialize Trazelet
import trazelet
trazelet.init()
Flask
from flask import Flask
from trazelet.integrations.flask import FlaskMiddleware
import trazelet
trazelet.init()
app = Flask(__name__)
app.wsgi_app = FlaskMiddleware(app=app)
@app.route("/")
def hello():
return "Hello World!"
Custom Configuration
import trazelet
# Custom database and settings
trazelet.init(
db_config={
"db_url": "postgresql+psycopg2://user:pass@localhost:5432/trazelet",
"echo": False
},
batch_size=100, # Batch size for bulk inserts
flush_interval=5.0, # Flush interval in seconds
max_workers=3, # Background worker threads
use_bulk_mode=True, # Enable bulk insert mode
logger_level="INFO" # Logging level
BUKCET_THRESHOLDS= [ # Set bucket threashold to classify for histogram in db
25, 50, 100,
200, 500, 1000,
1500, 3000, 5000
]
)
📊 What Gets Tracked?
Trazelet automatically captures:
- API Path: Normalized route patterns (e.g.,
/user/<id>instead of/user/123) - Latency: Request start/end times and elapsed duration
- Status Codes: HTTP response status codes
- Framework: Identifies which framework handled the request
- Timestamps: Precise request/response timestamps
Example Metrics:
/api/users/123 | 45ms | 200 | FastAPI | 2025-01-15 10:30:00
/api/users/456 | 120ms | 200 | FastAPI | 2025-01-15 10:30:01
/api/orders/789 | 15ms | 404 | FastAPI | 2025-01-15 10:30:02
🏗️ Architecture
Design Principles
- Non-Blocking: All database operations happen in background threads
- Thread-Safe: Uses
ThreadPoolExecutorand thread-safe queues - Invisible: Never crashes your application, all errors are caught and logged
- Efficient: Batch processing reduces database overhead
How It Works
Request → Middleware → Queue → Background Worker → Database
(<0.2ms) (O(1)) (Async) (Batched)
- Request arrives → Middleware captures start time
- Response sent → Middleware captures end time and queues metric
- Background worker → Processes queue in batches
- Database → Bulk inserts for performance
📊 Real-time Analytics & TUI
Trazelet isn't just about capturing data; it's about making that data actionable. The Trazelet Text User Interface (TUI), powered by src/trazelet/tui/app.py, provides a rich, interactive command-line experience to instantly visualize and analyze your API's performance.
Leveraging the robust Analytics Engine described in the Architecture Report, the TUI transforms raw metrics into comprehensive, human-readable reports right in your terminal.
Key TUI Features:
- ⚡ Instant Performance Insights: Get real-time health overviews and detailed metric breakdowns.
- 🎨 Rich, Interactive Output: Uses
Richlibrary for color-coded tables, panels, and progress spinners. - 🎯 Endpoint-Level Granularity: Analyze individual endpoint performance (latency, errors, throughput, Apdex).
- 🔍 Anomaly Detection: Quickly identify slowest or most error-prone endpoints.
- 📋 Flexible Reporting: View metrics in detailed tables, compact summaries, or JSON for programmatic use.
⚙️ Configuring Database Connection via CLI
The trazelet configure-db command sets up your database connection following a strict precedence order:
TRACELET_DB_URL: Highest priority, used if set in your environment.DATABASE_URL: Used if present, after prompting for confirmation.- Custom Environment Variable: Use
--env-var <NAME>to save an environment variable name in~/.trazelet/config.json. Trazelet will read the actual URL fromos.environ[NAME]on subsequent runs. - Default SQLite: If no other sources are found, Trazelet defaults to an internal SQLite database (
sqlite:///trazelet.db).
Use trazelet configure-db --reset to clear any previously saved custom environment variable name and re-evaluate the configuration.
Available Commands:
The Trazelet CLI (exposed via the trazelet command) offers the following powerful commands:
-
Get an operational health overview of all monitored endpoints, including health grades and distribution.
-
trazelet status -d last_24h
-
-
Dive into detailed analytics for all or specific endpoints, showing percentiles (P50, P95, P99), error rates, throughput, and Apdex scores.
trazelet describe -d "7 days" --sort p99 -f json
-
Highlight performance anomalies by listing the top N slowest or most error-prone endpoints.
trazelet top -m error -n 5
-
View a comprehensive list of all active endpoints being monitored, with filtering options by framework or HTTP method.
trazelet list --framework fastapi
📖 Documentation
Configuration Options
| Parameter | Type | Default | Description |
|---|---|---|---|
db_config |
dict | None |
Database configuration (uses SQLite if not provided) |
enabled |
bool | True |
Enable/disable Trazelet tracking |
batch_size |
int | 50 |
Number of metrics to batch before flushing |
flush_interval |
float | 5.0 |
Maximum seconds to wait before flushing queue data to DB |
max_workers |
int | 1 |
Background worker threads (1 for SQLite, configurable for Postgres) |
use_bulk_mode |
bool | True |
Enable bulk insert mode for performance |
logger_level |
str | "INFO" |
Logging level: DEBUG, INFO, WARNING, ERROR |
Database Configuration
SQLite (Default)
trazelet.init() # Uses SQLite automatically
PostgreSQL
trazelet.init(
db_config={
"db_url": "postgresql+psycopg2://user:password@localhost:5432/dbname",
"echo": False
},
max_workers=3 # Multiple workers for better throughput
)
Advanced Usage
Disable Trazelet Temporarily
trazelet.init(enabled=False) # Disables tracking without removing middleware
Custom Logging
trazelet.init(logger_level="DEBUG") # More verbose logging
Manual Flush
from trazelet.core.engine import get_engine
engine = get_engine()
engine.flush_buffer() # Manually flush queued metrics
📝 License
This project is licensed under the MIT License.
💡 Built With Purpose
- The Vision: A high-velocity performance tracker tailored for the modern era of API wrappers and micro-services.
- Privacy by Design: Instant analytics that stay in your environment. We provide the logic; you keep the data.
- Zero-Config Core: Works out of the box with sensible defaults, while offering minimal config for those who need it.
- Flexible Persistence: Plug into your existing PostgreSQL for production or stay lightweight with SQLite by default.
- The Community: Built for the developers who prioritize lean, efficient tools. Thank you to everyone helping us keep this project focused and fast!
📚 Additional Resources
- Architecture report - Comprehensive technical audit
- Testing report - Test suite documentation
- Tracker - Development roadmap and feature tracking
💬 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
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
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 trazelet-0.1.0.tar.gz.
File metadata
- Download URL: trazelet-0.1.0.tar.gz
- Upload date:
- Size: 37.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c907dba8f40cbdd72ebee342160038af669f0db561870a3ca6b57fb5c82b58c0
|
|
| MD5 |
fb3eb8b2601230a0ea03a884535c12f3
|
|
| BLAKE2b-256 |
b713a3a61d99d534c083ba0bdf46b5d8a2b0a6965484a8f1028c226e6e499ca1
|
File details
Details for the file trazelet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trazelet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cc0d63a3d40f5e3da3a5b961f3f77e37ad5166d5762b4e089434961af38e635
|
|
| MD5 |
34b3c601e6abd2a507ce32e324802e8b
|
|
| BLAKE2b-256 |
24a0467b7b69c88fcf05eb1b9b82b5fbc78c24d38c82bee0375cc4dbd57db3a2
|