Crate armature_analytics

Crate armature_analytics 

Source
Expand description

API Analytics Module for Armature Framework

Provides comprehensive API usage tracking, rate limit insights, and error monitoring.

§Features

  • Request Metrics: Track requests per endpoint, method, and status code
  • Latency Tracking: P50, P90, P95, P99 latency percentiles
  • Error Rates: Monitor error rates by endpoint and error type
  • Rate Limit Insights: Track rate limit hits, rejections, and usage patterns
  • Throughput Monitoring: Requests per second, minute, hour
  • Real-time Dashboard: JSON endpoint for analytics data

§Quick Start

use armature_analytics::{Analytics, AnalyticsMiddleware};
use armature_core::Application;

let analytics = Analytics::new(AnalyticsConfig::default());

let app = Application::new(container, router)
    .middleware(AnalyticsMiddleware::new(analytics.clone()));

// Access analytics endpoint
// GET /api/_analytics -> JSON dashboard data

§Architecture

┌─────────────────────────────────────────────────────────────┐
│                        Requests                              │
└─────────────────────────┬───────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                 AnalyticsMiddleware                          │
│  - Captures request/response metadata                        │
│  - Records timing, status, errors                            │
└─────────────────────────┬───────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                    MetricsCollector                          │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐       │
│  │ Requests │ │ Latency  │ │  Errors  │ │Rate Limit│       │
│  │ Counter  │ │Histogram │ │ Tracker  │ │ Insights │       │
│  └──────────┘ └──────────┘ └──────────┘ └──────────┘       │
└─────────────────────────┬───────────────────────────────────┘
                          │
                          ▼
┌─────────────────────────────────────────────────────────────┐
│                    Export Backends                           │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐                     │
│  │   JSON   │ │Prometheus│ │  Custom  │                     │
│  └──────────┘ └──────────┘ └──────────┘                     │
└─────────────────────────────────────────────────────────────┘

Structs§

Analytics
Main analytics instance
AnalyticsConfig
Configuration for the analytics module
AnalyticsConfigBuilder
Builder for AnalyticsConfig
AnalyticsContext
Request context for tracking within handlers
AnalyticsMiddleware
Middleware that automatically records analytics for all requests
AnalyticsSnapshot
Complete analytics snapshot for dashboard/export
ClientRateLimitInfo
Rate limit info for a specific client
EndpointMetrics
Per-endpoint metrics
ErrorMetrics
Error metrics summary
ErrorRecord
Record of an error for analytics
ErrorSummary
Summary of a recent error
HistogramValue
Histogram metric value with buckets
Insight
An analytics insight
InsightConfig
Configuration for insight detection
InsightGenerator
Insight generator
LatencyMetrics
Latency metrics with percentiles
Metric
Named metric with labels
MetricsCollector
Thread-safe metrics collector
RateLimitEvent
Record of a rate limit event
RateLimitMetrics
Rate limit metrics
RequestMetrics
Request metrics summary
RequestRecord
Record of a single request for analytics
ThroughputMetrics
Throughput metrics
TimeSeries
Time series data
TimeSeriesPoint
Time series data point
TrackedHandler
Handler wrapper that automatically tracks analytics

Enums§

AnalyticsError
Errors that can occur in the analytics module
InsightType
Types of insights
MetricType
Metric types
MetricValue
Metric value types
RateLimitEventType
Rate limit event types
Severity
Severity levels

Traits§

AnalyticsExt
Extension trait for adding analytics to requests
DurationExt
Duration formatting helpers

Functions§

normalize_path
Helper to normalize request paths for aggregation