embeddenator-obs
Comprehensive observability infrastructure for the Embeddenator ecosystem.
Independent component extracted from the Embeddenator monolithic repository. Part of the Embeddenator workspace.
Repository: https://github.com/tzervas/embeddenator-obs
Overview
embeddenator-obs provides production-grade observability components:
- Metrics: Lock-free atomic counters for high-performance tracking
- Logging: Structured logging with environment-based filtering
- Tracing: Span instrumentation for distributed tracing
- Telemetry: Aggregation and export of observability data
- Hi-Res Timing: Picosecond-scale timing measurements
- Test Metrics: Comprehensive performance analysis for testing
Status
Phase 2A Component Extraction - Fully migrated from embeddenator core.
Implementation: Core features complete, optional integrations available.
Features
Default Features
metrics: Atomic performance counters (zero-overhead when not sampled)
Optional Features
tracing: Span instrumentation and distributed tracinglogging: Structured logging (requirestracing)telemetry: Aggregation and JSON exportprometheus: Prometheus metrics export formatopentelemetry: OpenTelemetry/OTLP distributed tracingstreaming: Real-time metric streaming with callbacksadvanced-stats: Advanced statistical analysis (percentiles, std dev)full: Enable all features
Installation
[]
= { = "https://github.com/tzervas/embeddenator-obs", = "v0.20.0-alpha.1" }
# Or with all features
= { = "https://github.com/tzervas/embeddenator-obs", = "v0.20.0-alpha.1", = ["full"] }
Usage
Quick Start
use ;
use Duration;
Metrics
Lock-free atomic counters for production use:
use metrics;
use Duration;
// Increment counters
metrics.inc_sub_cache_hit;
metrics.inc_sub_cache_miss;
metrics.inc_index_cache_eviction;
// Record operation timing
metrics.record_retrieval_query;
metrics.record_rerank;
// Get snapshot for monitoring
let snapshot = metrics.snapshot;
println!;
Logging
Environment-based structured logging:
# Set log level
# or
# Set output format
# json, pretty, or compact
use ;
info;
warn;
error;
debug;
Tracing
Span instrumentation for performance analysis:
use create_span;
Test Metrics
Comprehensive performance tracking for tests:
use TestMetrics;
use Duration;
Telemetry
Aggregate and export observability data:
use ;
let mut telemetry = default_config;
// Record operations
telemetry.record_operation; // microseconds
telemetry.increment_counter;
telemetry.set_gauge;
// Export snapshot
let snapshot = telemetry.snapshot;
println!; // JSON export
println!; // Human-readable
Hi-Res Timing
Picosecond-scale timing for micro-benchmarks:
use ;
// Single measurement
let timer = start;
// ... work ...
let elapsed = timer.elapsed;
println!;
// Measure closure
let = measure;
// Multiple measurements with statistics
let = measure_n;
println!;
Integration with Other Components
In embeddenator-vsa
use ;
In embeddenator-retrieval
use ;
use Instant;
Performance Overhead
- Metrics (feature disabled): 0ns - compiles to no-op
- Metrics (feature enabled): ~5-10ns per counter increment
- Tracing (feature disabled): 0ns - compiles to no-op
- Tracing (feature enabled): ~50-100ns per span
- Hi-Res Timing: ~20-50ns per measurement
All overhead is pay-for-what-you-use via feature flags.
Development
# Build with default features
# Build with all features
# Run tests
# Run specific test
Testing
# Unit tests
# Integration tests
# With verbose output
Cross-Repo Development
For local development across Embeddenator components:
[]
= { = "../embeddenator-obs" }
Migration Notes
Migrated from embeddenator core:
testing::TestMetrics→embeddenator_obs::TestMetricsobs::metrics→embeddenator_obs::metricsobs::logging→embeddenator_obs::logging- Hi-res timing infrastructure preserved
- All existing functionality maintained
New additions:
- Span-based tracing infrastructure
- Telemetry aggregation and export
- Enhanced logging with multiple formats
- Comprehensive integration tests
Architecture
See ADR-016 for component decomposition rationale.
Advanced Features
Prometheus Metrics Export
Export metrics in Prometheus text format for scraping:
use ;
let mut telemetry = default_config;
telemetry.record_operation;
telemetry.increment_counter;
let snapshot = telemetry.snapshot;
let exporter = new;
let prometheus_text = exporter.export;
// Serve at /metrics endpoint
println!;
Output format:
# HELP embeddenator_requests Counter metric
# TYPE embeddenator_requests counter
embeddenator_requests 42
# HELP embeddenator_query_duration_us Operation duration histogram
# TYPE embeddenator_query_duration_us histogram
embeddenator_query_duration_us_bucket{le="100"} 5
embeddenator_query_duration_us_bucket{le="500"} 15
...
OpenTelemetry Distributed Tracing
W3C Trace Context compatible spans for distributed systems:
use ;
// Create root span
let mut span = new;
span.set_attribute;
span.add_event;
// Create child span
let mut child = new_child;
child.end;
span.end;
// Export trace context (propagate to downstream services)
let traceparent = span.to_traceparent;
// Send as HTTP header: traceparent: 00-<trace_id>-<span_id>-01
Advanced Statistical Analysis
Percentiles, standard deviation, and histogram buckets:
use Telemetry;
let mut telemetry = default_config;
// Record many samples
for i in 1..=1000
let snapshot = telemetry.snapshot;
let stats = snapshot.operation_stats.get.unwrap;
println!;
println!;
println!;
println!;
println!;
// Histogram buckets for Prometheus
let below_1ms = stats.count_below;
Real-Time Metric Streaming
Callback-based streaming for live monitoring and alerting:
use ;
let mut stream = new;
// Add threshold alerts
stream.add_threshold_alert;
// Subscribe to events
stream.subscribe;
// Publish metrics
stream.publish_counter;
stream.publish_gauge; // Triggers alert
Examples
# Run advanced features demo
# Run performance benchmark
License
MIT