llm_analytics_hub/
lib.rs

1//! LLM Analytics Hub
2//!
3//! Centralized analytics hub for the LLM ecosystem, providing comprehensive
4//! data models and schemas for telemetry, security, cost, and governance monitoring.
5//!
6//! # Overview
7//!
8//! This crate provides:
9//! - **Event Schemas**: Unified event schema for telemetry, security, cost, and governance
10//! - **Metrics Models**: Time-window aggregations with statistical measures
11//! - **Time-Series Models**: Tag-based organization for efficient querying
12//! - **Correlation Schemas**: Cross-module event correlation and anomaly detection
13//! - **Metadata Schemas**: Asset, policy, dashboard, and user preference models
14//! - **API Models**: Response formats, pagination, error handling, and streaming
15//!
16//! # Example
17//!
18//! ```rust
19//! use llm_analytics_hub::schemas::events::{AnalyticsEvent, CommonEventFields, EventPayload};
20//! use llm_analytics_hub::models::metrics::{MetricType, CounterMetric};
21//! use chrono::Utc;
22//!
23//! // Create a telemetry event
24//! let event = AnalyticsEvent {
25//!     common: CommonEventFields {
26//!         event_id: uuid::Uuid::new_v4(),
27//!         timestamp: Utc::now(),
28//!         source_module: llm_analytics_hub::schemas::events::SourceModule::LlmObservatory,
29//!         event_type: llm_analytics_hub::schemas::events::EventType::Telemetry,
30//!         correlation_id: None,
31//!         parent_event_id: None,
32//!         schema_version: "1.0.0".to_string(),
33//!         severity: llm_analytics_hub::schemas::events::Severity::Info,
34//!         environment: "production".to_string(),
35//!         tags: std::collections::HashMap::new(),
36//!     },
37//!     payload: EventPayload::Custom(llm_analytics_hub::schemas::events::CustomPayload {
38//!         custom_type: "example".to_string(),
39//!         data: serde_json::json!({"key": "value"}),
40//!     }),
41//! };
42//! ```
43
44pub mod schemas {
45    //! Schema definitions for events and metadata
46
47    pub mod events;
48    pub mod metadata;
49}
50
51pub mod models {
52    //! Data models for metrics, time-series, correlation, and API responses
53
54    pub mod metrics;
55    pub mod timeseries;
56    pub mod correlation;
57    pub mod api;
58}
59
60pub mod database;
61pub mod pipeline;
62pub mod analytics;
63pub mod resilience;
64
65// CLI and infrastructure modules
66pub mod cli;
67pub mod common;
68pub mod infra;
69
70// Re-export commonly used types at the crate root
71pub use database::Database;
72pub use pipeline::ingestion::{EventIngester, IngestionConfig, IngestionStats};
73pub use analytics::anomaly::{AnomalyDetector, Anomaly, AnomalyType, AnomalySeverity};
74pub use analytics::{CorrelationEngine, AggregationEngine};
75pub use schemas::events::{
76    AnalyticsEvent, CommonEventFields, EventPayload, EventType, Severity, SourceModule,
77};
78
79pub use models::metrics::{
80    AggregatedMetric, CounterMetric, GaugeMetric, HistogramMetric, MetricType,
81    StatisticalMeasures, TimeWindow,
82};
83
84pub use models::timeseries::{
85    FieldSet, IndexConfig, RetentionPolicy, TagSet, TimeSeriesPoint, TimeSeriesQuery,
86};
87
88pub use models::correlation::{
89    AnomalyCorrelation, CorrelationId, CorrelationType, EventCorrelation, EventGraph,
90    RootCauseAnalysis,
91};
92
93pub use models::api::{
94    ApiError, ApiResponse, PaginatedResponse, PaginationMetadata, QueryResult, StreamEvent,
95};
96
97/// Version information
98pub const VERSION: &str = env!("CARGO_PKG_VERSION");
99
100/// Schema version for data compatibility
101pub const SCHEMA_VERSION: &str = "1.0.0";
102
103#[cfg(test)]
104mod tests {
105    use super::*;
106
107    #[test]
108    fn test_version_constants() {
109        assert!(!VERSION.is_empty());
110        assert_eq!(SCHEMA_VERSION, "1.0.0");
111    }
112}