Trace, analyze, and monitor Python application execution with configurable policies and multiple output formats.
Project description
๐ Glimpse
Function-level logging and tracing for Python applications.
Glimpse automatically captures your application's execution flow, giving you detailed insights into function calls, performance, and errors. Think of it as a microscope for your code - see exactly what's happening, when, and why.
Built by developers, for developers who need to understand their code better.
โจ Why Glimpse?
Get visibility into your application without changing your code. Glimpse automatically traces function execution, captures arguments and return values, and logs everything to your preferred storage backend.
Perfect for debugging complex applications, performance analysis, and understanding code flow in production systems.
Key Benefits:
- ๐ Zero-code tracing - Just run
tracer.run()and see everything - ๐ฏ Smart filtering - Only trace what matters with flexible policies
- ๐ Multiple backends - Store traces in JSON, JSONL, SQLite, or build your own
- โก Performance optimized - Minimal overhead, designed for production use
- ๐ง Developer friendly - Simple setup, clear output, easy integration
๐ Quick Start
Installation
pip install glimpse-py
30-Second Example
from glimpse.tracer import Tracer
from glimpse.config import Config
from glimpse.policy import TracingPolicy
# Configure what to trace
config = Config(dest="jsonl", level="INFO")
policy = TracingPolicy(exact_modules=["myapp"], package_trees=["myapp.services"])
# Start automatic tracing
tracer = Tracer(config, policy=policy)
tracer.run()
# Your code runs here - everything gets traced automatically
def calculate_total(items):
return sum(item.price for item in items)
result = calculate_total(shopping_cart)
tracer.stop()
That's it! Every function call matching your policy is now logged with timing, arguments, and results.
๐ ๏ธ Core Features
Automatic Function Tracing
Trace all function calls without decorators. Just call tracer.run() and Glimpse automatically captures execution flow based on your policy.
# Traces everything matching your policy
tracer.run()
your_application_code()
tracer.stop()
Manual Decorators
Fine-grained control for specific functions. Use decorators when you want explicit tracing of important functions.
@tracer.trace_function
def critical_function(data):
# This function will always be traced
return process_data(data)
Multiple Storage Backends
Store traces wherever you need them. Built-in support for JSON, JSONL, and SQLite.
from glimpse.config import Config
# JSON Lines (great for log analysis)
config = Config(dest="jsonl", params={"log_path": "/var/logs/traces.jsonl"})
# SQLite (great for local development and analysis)
config = Config(dest="sqlite", params={"db_path": "traces.db"})
# Multiple destinations simultaneously
config = Config(dest=["jsonl", "sqlite"])
Smart Policy System
Control exactly what gets traced. Use JSON policies to include/exclude packages with powerful pattern matching.
from glimpse.policy import TracingPolicy
# Programmatic policy creation
policy = TracingPolicy(
exact_modules=["myapp.utils", "requests"], # Exact module matches only
package_trees=["myapp.services"], # Package + all submodules
trace_depth=10 # Prevent infinite recursion
)
# Load from JSON file
policy = TracingPolicy.load("my-custom-policy.json")
# Auto-discover policy file
policy = TracingPolicy.load() # Finds closest glimpse-policy.json
Context Manager Support
Clean, Pythonic usage. Automatically start and stop tracing with context managers.
with Tracer(config, policy=policy):
# Tracing active only in this block
run_my_application()
# Tracing automatically stops and cleans up
โ๏ธ Configuration
Basic Configuration
Configure storage, log levels, and output format. Settings can be provided via constructor or environment variables.
from glimpse.config import Config
# Constructor approach
config = Config(
dest="jsonl", # Storage backend: jsonl, json, sqlite
level="INFO", # Log level
enable_trace_id=True, # Enable trace correlation
params={"log_path": "/var/logs/traces.jsonl"},
max_field_length=512 # Truncate long values
)
# Environment variable approach
# GLIMPSE_DEST=jsonl
# GLIMPSE_LEVEL=DEBUG
# GLIMPSE_LOG_PATH=/var/logs/traces.jsonl
config = Config() # Automatically loads from environment
Environment Variables
All configuration can be controlled via environment variables:
| Variable | Description | Default |
|---|---|---|
GLIMPSE_DEST |
Storage backend (jsonl, sqlite) | jsonl |
GLIMPSE_LEVEL |
Log level (INFO, DEBUG, ERROR) | INFO |
GLIMPSE_LOG_PATH |
Path to log file | glimpse.jsonl |
GLIMPSE_TRACE_ID |
Enable trace correlation | false |
๐ Policy System
Policy Files
Control tracing behavior with JSON policies. Create policy files to define what gets traced.
{
"version": "1.0",
"name": "my_policy",
"exact_modules": ["mylib", "requests"],
"package_trees": ["myapp", "services"],
"trace_depth": 5
}
Policy Types
Two distinct filtering approaches for maximum flexibility:
exact_modules: Match only the exact module names specified (no submodules)package_trees: Match the package and ALL its submodules
from glimpse.policy import TracingPolicy
policy = TracingPolicy(
exact_modules=["requests", "urllib3"], # Only these exact modules
package_trees=["myapp", "services"], # These packages + submodules
trace_depth=10
)
Wildcard Patterns
Use powerful patterns to match modules. Support for shell-style wildcards:
{
"exact_modules": [
"api_v*", // Matches: api_v1, api_v2, api_version_new
"test_*_utils", // Matches: test_unit_utils, test_integration_utils
"config[12]" // Matches: config1, config2
],
"package_trees": [
"myapp.*", // Matches: myapp.services, myapp.utils, etc.
"*.models" // Matches: core.models, user.models, etc.
]
}
Policy Discovery
Automatic policy discovery. Glimpse walks up your directory tree to find the closest policy file.
# Auto-discover from caller location
policy = TracingPolicy.load()
# Explicit path (must be named 'glimpse-policy.json')
policy = TracingPolicy.load("/path/to/glimpse-policy.json")
myproject/
โโโ glimpse-policy.json # Found and used automatically
โโโ src/
โ โโโ myapp/
โ โโโ main.py # TracingPolicy.load() called here
โโโ tests/
๐ Output Examples
JSONL Output
Each function call produces a structured log entry. Easy to analyze with standard tools like jq, ELK stack, or pandas.
{"entry_id": "1234-a1b2c3d4-000001", "call_id": "abc123def456", "trace_id": "xyz789uvw012", "level": "INFO", "function": "myapp.services.get_user", "args": "get_user(user_id=123)", "stage": "START", "timestamp": "2023-12-01 10:30:15.123456"}
{"entry_id": "1234-a1b2c3d4-000002", "call_id": "abc123def456", "trace_id": "xyz789uvw012", "level": "INFO", "function": "myapp.services.get_user", "args": "get_user", "stage": "END", "result": "User(id=123, name='John')", "timestamp": "2023-12-01 10:30:15.145223", "duration_ms": "21.767"}
SQLite Output
Structured database storage for complex analysis. Query your traces with SQL for powerful insights.
-- Find slow functions
SELECT function, AVG(duration_ms) as avg_duration
FROM trace_entries
WHERE stage = 'END'
GROUP BY function
ORDER BY avg_duration DESC;
-- Find error patterns
SELECT function, COUNT(*) as error_count
FROM trace_entries
WHERE stage = 'EXCEPTION'
GROUP BY function;
-- Trace correlation by call_id
SELECT * FROM trace_entries
WHERE call_id = 'abc123def456'
ORDER BY timestamp;
Trace Analysis
Easily analyze execution patterns:
# Find slow functions (JSONL)
cat traces.jsonl | jq 'select(.duration_ms > 100)'
# Count function calls
cat traces.jsonl | jq '.function' | sort | uniq -c
# Find errors
cat traces.jsonl | jq 'select(.stage == "EXCEPTION")'
# Trace specific call flow
cat traces.jsonl | jq 'select(.call_id == "abc123def456")'
๐๏ธ Architecture
High-Level Design
Modular architecture designed for extensibility. Each component has a single responsibility and can be extended or replaced.
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Tracer โโโโโถโ Policy โโโโโถโ Writer โ
โ โ โ โ โ โ
โ โข Manual โ โ โข Exact Mods โ โ โข JSON โ
โ โข Automatic โ โ โข Pkg Trees โ โ โข JSONL โ
โ โข Context โ โ โข Wildcards โ โ โข SQLite โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
Component Overview
- Tracer: Core tracing engine using
sys.settrace() - TracingPolicy: Smart filtering with exact modules vs package trees
- Config: Environment-aware configuration management
- Writers: Pluggable storage backends (JSON, JSONL, SQLite)
- LogEntry: Structured trace data model with correlation IDs
- IDGenerator: Thread-safe ID generation for tracing correlation
Performance Characteristics
Designed for production use. Optimized hot paths, minimal overhead, and efficient pattern matching.
- โก Efficient pattern matching using tries and sets
- ๐ฏ Smart filtering to avoid tracing unnecessary code
- ๐ Configurable depth limits to prevent runaway traces
- ๐ง Self-filtering to avoid tracing the tracer itself
- ๐งต Thread-safe ID generation and SQLite operations
๐ Upcoming Features
Enhanced Policy System
More sophisticated filtering and configuration options. Coming soon: regex patterns, performance-based filtering, and dynamic policies.
Distributed System Support
Trace across multiple services and processes. Coming soon: trace correlation, request IDs, and cross-service visibility.
Additional Storage Backends
More storage options. Planned: MongoDB, Elasticsearch, and cloud storage integrations.
Custom Writers
Build your own storage backends. Simple interface for integrating with any storage system.
# Future: Custom storage backends
from glimpse.writers.base import BaseWriter
class ElasticsearchWriter(BaseWriter):
def write(self, entry):
# Your custom logic here
pass
๐ค Contributing
Found a bug? Have a feature request? Want to contribute code?
- ๐ Open an issue
- ๐ Submit a pull request
- ๐ฌ Start a discussion
Built by developers, for developers. Your feedback and contributions make Glimpse better for everyone.
๐ License
MIT License - see LICENSE for details.
โญ Like Glimpse? Give us a star and help other developers discover it!
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 glimpse_py-0.1.0.tar.gz.
File metadata
- Download URL: glimpse_py-0.1.0.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47acd43e3154b2a0782da7ee1199991b4503620c3a16a4d58d99e02e198aa374
|
|
| MD5 |
fe43711f820970abf5a97e49b77177f5
|
|
| BLAKE2b-256 |
d5ce6dee96dca7db0c93e50b6628141fb0ae60013a0b3d2957fcc99e31c4a584
|
File details
Details for the file glimpse_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: glimpse_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
071cafdce301b3f95943b436ccfb0c24748839cfc4a21b9f5012ebb711438fd1
|
|
| MD5 |
a9268992fc0f11b16542189e3157c4be
|
|
| BLAKE2b-256 |
2fe0bd46c9fb0dd38735c2cf9aee7ca4a7722772b4d7414863aefabf6b887004
|