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 {
23 PLATFORM_OWNER.get_or_init(|| admin)
24}
25
26pub fn platform_attribution() -> Result<&'static SystemAdmin, LogAttributionUnset> {
27 PLATFORM_OWNER.get().ok_or(LogAttributionUnset)
28}
29
30pub(crate) fn platform_owner_id() -> Result<&'static UserId, LogAttributionUnset> {
31 platform_attribution().map(SystemAdmin::id)
32}
33
34#[derive(Debug, Clone, Copy, Error)]
35#[error("log attribution not installed: AppContext bootstrap must run before platform log events")]
36pub struct LogAttributionUnset;