Observability Library
The @lssm/lib.observability library provides a thin wrapper around OpenTelemetry to simplify instrumentation.
Tracing
import { traceAsync, traceSync } from '@lssm/lib.observability/tracing';
await traceAsync('process_order', async (span) => {
span.setAttribute('order_id', order.id);
await db.save(order);
});Metrics
import { createCounter, createHistogram } from '@lssm/lib.observability/metrics';
const ordersCounter = createCounter('orders_total');
const latencyHistogram = createHistogram('request_duration_seconds');
ordersCounter.add(1, { status: 'success' });
latencyHistogram.record(0.123);Middleware
Automatically instrument your HTTP handlers:
import { createTracingMiddleware } from '@lssm/lib.observability/tracing/middleware';
app.use(createTracingMiddleware());Anomaly Detection
Includes baseline calculation and anomaly detection helpers for auto-rollback without writing custom math.
import { AnomalyDetector, RootCauseAnalyzer, AlertManager } from '@lssm/lib.observability';
const detector = new AnomalyDetector({ errorRateDelta: 0.4 });
const analyzer = new RootCauseAnalyzer();
const alertManager = new AlertManager({ transport: sendOpsAlert });
const signals = detector.evaluate(point);
signals.forEach((signal) => {
const analysis = analyzer.analyze(signal, recentDeployments);
alertManager.notify(signal, analysis);
});