systemprompt-analytics 0.60.0

Analytics for systemprompt.io AI governance infrastructure. Session, agent, tool, and microdollar-precision cost attribution across the MCP governance pipeline.
Documentation
//! Analytics domain crate for systemprompt.io.
//!
//! Provides session, fingerprint, engagement, conversation, content,
//! tool, agent, and cost analytics on top of the `systemprompt-database`
//! abstraction. Public surface is a typed [`AnalyticsError`] boundary plus a
//! family of repositories and services consumed by `systemprompt-api`,
//! `systemprompt-cli`, and `systemprompt-scheduler`.
//!
//! # Feature flags
//!
//! | Feature       | Description                                                                  |
//! |---------------|------------------------------------------------------------------------------|
//! | _(default)_   | Core analytics — repositories, services, events, no geolocation enrichment.  |
//! | `geolocation` | Enables `MaxMind` `GeoIP` enrichment via `maxminddb` for [`GeoIpReader`].        |
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

pub mod error;
pub mod extension;
pub mod models;
pub mod repository;
pub mod resource_metrics;
pub mod services;

pub use extension::AnalyticsExtension;

pub use error::{AnalyticsError, Result, Result as AnalyticsResult};

pub use models::{
    AnalyticsEventBatchResponse, AnalyticsEventCreated, AnalyticsEventType, AnalyticsSession,
    ContextGroupRow, ContextSummaryRow, ConversionEventData, CreateAnalyticsEventBatchInput,
    CreateAnalyticsEventInput, CreateEngagementEventInput, EngagementEvent, EngagementEventData,
    EngagementOptionalMetrics, FingerprintAnalysisResult, FingerprintReputation, FlagReason,
    LinkClickEventData, RecentContextRow, ScrollEventData,
};
pub use repository::{
    ABUSE_THRESHOLD_FOR_BAN, AgentAnalyticsRepository, AnalyticsEventsRepository,
    CliSessionAnalyticsRepository, ContentAnalyticsRepository, ConversationAnalyticsRepository,
    CostAnalyticsRepository, CreateSessionParams, EngagementRepository, FingerprintRepository,
    HIGH_REQUEST_THRESHOLD, HIGH_VELOCITY_RPM, MAX_SESSIONS_PER_FINGERPRINT, NavigationQuery,
    OverviewAnalyticsRepository, PageQuery, RequestAnalyticsRepository, SUSTAINED_VELOCITY_MINUTES,
    SessionBehavioralData, SessionMigrationResult, SessionRecord, SessionRepository,
    ToolAnalyticsRepository, ToolListParams, TrafficAnalyticsRepository,
};
pub use services::bot_keywords::matches_bot_pattern;
pub use services::{
    AnalyticsService, BEHAVIORAL_BOT_THRESHOLD, BehavioralAnalysisInput, BehavioralAnalysisResult,
    BehavioralBotDetector, BehavioralSignal, ProfileUsageService, SessionAnalytics,
    SessionAnalyticsBuilder, SignalType, detection,
};

#[cfg(feature = "geolocation")]
pub type GeoIpReader = std::sync::Arc<maxminddb::Reader<Vec<u8>>>;

#[cfg(not(feature = "geolocation"))]
pub type GeoIpReader = std::sync::Arc<()>;