Quickstart
Install
Section titled “Install”uv add lexigram-monitorFor production monitoring, install your backend extra:
# Prometheus metricsuv add "lexigram-monitor[prometheus]"# OpenTelemetry tracing (OTLP)uv add "lexigram-monitor[otel]"# System metrics (CPU, memory)uv add "lexigram-monitor[system]"# All extrasuv add "lexigram-monitor[all]"Minimal Example
Section titled “Minimal Example”import asyncio
from lexigram import Application, LexigramConfigfrom lexigram.monitor import MonitorProviderfrom lexigram.monitor.noop import NoOpMetricsBackend
async def main(): config = LexigramConfig.from_yaml("application.yaml") app = Application(name="my-app", config=config) app.add_provider(MonitorProvider(backend=NoOpMetricsBackend()))
async with app.boot(): # Create and increment a counter provider = await app.container.resolve(MonitorProvider) counter = provider.create_counter("requests_total", "Total requests") counter.increment() counter.increment(5) print(f"Count: {counter.get_count()}")
# Record an HTTP request provider.record_request("GET", "/api/users", 0.125, 200)
# Read health health = await provider.health_check() print(f"Status: {health.status}")
asyncio.run(main())Wiring
Section titled “Wiring”Add MonitorProvider to your Application. The provider auto-discovers MonitorConfig from the monitor: section of your YAML config:
from lexigram.monitor import MonitorProviderfrom lexigram.monitor.config import MonitorConfig
# In-memory (development / testing)app.add_provider(MonitorProvider(backend=NoOpMetricsBackend()))
# From config — reads LEX_MONITOR__* env varsprovider = MonitorProvider.from_config(MonitorConfig())app.add_provider(provider)Or use the declarative MonitorModule:
from lexigram.monitor import MonitorModulefrom lexigram.monitor.backends.prometheus import PrometheusBackend
app.add_module(MonitorModule.configure(backend=PrometheusBackend()))What Just Happened
Section titled “What Just Happened”MonitorProviderregistered singletons forMetricsCollectorProtocol,TracerProtocol, andHealthCheckRegistryProtocol- The
@tracedand@metereddecorators now resolve real implementations from the container health_check()returns component status with backend type and metric count
Next Steps
Section titled “Next Steps”- Guide — mental model, core concepts, best practices
- Configuration — every config key with defaults and env vars
- How-Tos — common recipes