systemprompt_logging/
attribution.rs1use std::sync::OnceLock;
14use systemprompt_identifiers::UserId;
15use systemprompt_models::services::SystemAdmin;
16use thiserror::Error;
17
18static PLATFORM_OWNER: OnceLock<SystemAdmin> = OnceLock::new();
19
20pub fn install_log_attribution(admin: SystemAdmin) -> &'static SystemAdmin {
22 PLATFORM_OWNER.get_or_init(|| admin)
23}
24
25pub fn platform_attribution() -> Result<&'static SystemAdmin, LogAttributionUnset> {
26 PLATFORM_OWNER.get().ok_or(LogAttributionUnset)
27}
28
29pub(crate) fn platform_owner_id() -> Result<&'static UserId, LogAttributionUnset> {
30 platform_attribution().map(SystemAdmin::id)
31}
32
33#[derive(Debug, Clone, Copy, Error)]
34#[error("log attribution not installed: AppContext bootstrap must run before platform log events")]
35pub struct LogAttributionUnset;