Skip to main content

systemprompt_analytics/
lib.rs

1//! Analytics domain crate for systemprompt.io.
2//!
3//! Provides session, fingerprint, funnel, 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 feedback;
22pub mod models;
23pub mod projection;
24pub mod repository;
25pub mod resource_metrics;
26pub mod services;
27
28pub use extension::AnalyticsExtension;
29
30pub use error::{AnalyticsError, Result, Result as AnalyticsResult};
31
32pub use models::{
33    ActivityTrend, AnalyticsEvent, AnalyticsEventBatchResponse, AnalyticsEventCreated,
34    AnalyticsEventType, AnalyticsSession, BotTrafficStats, BrowserBreakdown, ContentStat,
35    ContextGroupRow, ContextSummaryRow, ConversationByAgent, ConversationSummary,
36    ConversationTrend, ConversionEventData, CostOverview, CreateAnalyticsEventBatchInput,
37    CreateAnalyticsEventInput, CreateEngagementEventInput, CreateFunnelInput,
38    CreateFunnelStepInput, DeviceBreakdown, EngagementEvent, EngagementEventData,
39    EngagementOptionalMetrics, ErrorSummary, FingerprintAnalysisResult, FingerprintReputation,
40    FlagReason, Funnel, FunnelMatchType, FunnelProgress, FunnelStats, FunnelStep, FunnelStepStats,
41    FunnelWithSteps, GeographicBreakdown, LinkClickEventData, PlatformOverview, RecentContextRow,
42    RecentConversation, ScrollEventData, TopAgent, TopTool, TopUser, TrafficSource, TrafficSummary,
43    UserMetricsWithTrends,
44};
45pub use repository::{
46    ABUSE_THRESHOLD_FOR_BAN, AgentAnalyticsRepository, AnalyticsEventsRepository,
47    AnalyticsQueryRepository, CliSessionAnalyticsRepository, ContentAnalyticsRepository,
48    ConversationAnalyticsRepository, CoreStatsRepository, CostAnalyticsRepository,
49    CreateSessionParams, EngagementRepository, FingerprintRepository, FunnelRepository,
50    HIGH_REQUEST_THRESHOLD, HIGH_VELOCITY_RPM, MAX_SESSIONS_PER_FINGERPRINT, NavigationQuery,
51    OverviewAnalyticsRepository, PageQuery, ProviderUsage, RequestAnalyticsRepository,
52    SUSTAINED_VELOCITY_MINUTES, SessionBehavioralData, SessionEngagementSummary,
53    SessionMigrationResult, SessionRecord, SessionRepository, StoredAnalyticsEvent,
54    ToolAnalyticsRepository, ToolListParams, TrafficAnalyticsRepository,
55};
56pub use services::bot_keywords::matches_bot_pattern;
57pub use services::{
58    AnalyticsService, AnomalyCheckResult, AnomalyDetectionService, AnomalyEvent, AnomalyLevel,
59    AnomalyThresholdConfig, BEHAVIORAL_BOT_THRESHOLD, BehavioralAnalysisInput,
60    BehavioralAnalysisResult, BehavioralBotDetector, BehavioralSignal, ProfileUsageService,
61    SessionAnalytics, SessionAnalyticsBuilder, SignalType, detection,
62};
63
64#[cfg(feature = "geolocation")]
65pub type GeoIpReader = std::sync::Arc<maxminddb::Reader<Vec<u8>>>;
66
67#[cfg(not(feature = "geolocation"))]
68pub type GeoIpReader = std::sync::Arc<()>;
69
70pub mod snapshots;