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