Skip to main content

systemprompt_analytics/
lib.rs

1//! Analytics domain crate for systemprompt.io.
2//!
3//! Provides session, fingerprint, engagement, conversation, content,
4//! tool, agent, and cost analytics on top of the `systemprompt-database`
5//! abstraction. Public surface is a typed [`AnalyticsError`] boundary plus a
6//! family of repositories and services consumed by `systemprompt-api`,
7//! `systemprompt-cli`, and `systemprompt-scheduler`.
8//!
9//! # Feature flags
10//!
11//! | Feature       | Description                                                                  |
12//! |---------------|------------------------------------------------------------------------------|
13//! | _(default)_   | Core analytics — repositories, services, events, no geolocation enrichment.  |
14//! | `geolocation` | Enables `MaxMind` `GeoIP` enrichment via `maxminddb` for [`GeoIpReader`].        |
15//!
16//! Copyright (c) systemprompt.io — Business Source License 1.1.
17//! See <https://systemprompt.io> for licensing details.
18
19pub mod error;
20pub mod extension;
21pub mod models;
22pub mod repository;
23pub mod resource_metrics;
24pub mod services;
25
26pub use extension::AnalyticsExtension;
27
28pub use error::{AnalyticsError, Result, Result as AnalyticsResult};
29
30pub use models::{
31    AnalyticsEventBatchResponse, AnalyticsEventCreated, AnalyticsEventType, AnalyticsSession,
32    ContextGroupRow, ContextSummaryRow, ConversionEventData, CreateAnalyticsEventBatchInput,
33    CreateAnalyticsEventInput, CreateEngagementEventInput, EngagementEvent, EngagementEventData,
34    EngagementOptionalMetrics, FingerprintAnalysisResult, FingerprintReputation, FlagReason,
35    LinkClickEventData, RecentContextRow, ScrollEventData,
36};
37pub use repository::{
38    ABUSE_THRESHOLD_FOR_BAN, AgentAnalyticsRepository, AnalyticsEventsRepository,
39    CliSessionAnalyticsRepository, ContentAnalyticsRepository, ConversationAnalyticsRepository,
40    CostAnalyticsRepository, CreateSessionParams, EngagementRepository, FingerprintRepository,
41    HIGH_REQUEST_THRESHOLD, HIGH_VELOCITY_RPM, MAX_SESSIONS_PER_FINGERPRINT, NavigationQuery,
42    OverviewAnalyticsRepository, PageQuery, RequestAnalyticsRepository, SUSTAINED_VELOCITY_MINUTES,
43    SessionBehavioralData, SessionMigrationResult, SessionRecord, SessionRepository,
44    ToolAnalyticsRepository, ToolListParams, TrafficAnalyticsRepository,
45};
46pub use services::bot_keywords::matches_bot_pattern;
47pub use services::{
48    AnalyticsService, BEHAVIORAL_BOT_THRESHOLD, BehavioralAnalysisInput, BehavioralAnalysisResult,
49    BehavioralBotDetector, BehavioralSignal, ProfileUsageService, SessionAnalytics,
50    SessionAnalyticsBuilder, SignalType, detection,
51};
52
53#[cfg(feature = "geolocation")]
54pub type GeoIpReader = std::sync::Arc<maxminddb::Reader<Vec<u8>>>;
55
56#[cfg(not(feature = "geolocation"))]
57pub type GeoIpReader = std::sync::Arc<()>;