diff --git a/apps/desktop/src-tauri/src/backend.rs b/apps/desktop/src-tauri/src/backend.rs index 4571aa3cbd..bc12ebdee6 100644 --- a/apps/desktop/src-tauri/src/backend.rs +++ b/apps/desktop/src-tauri/src/backend.rs @@ -76,7 +76,14 @@ where let backend = backend.clone(); scope.add_event_processor(move |mut event| { event.user = Some(sentry_user()).map(|mut user| { - user.username = backend.user(); + let auth = backend.user(); + user.id = backend + .analytics + .as_ref() + .zip(auth.clone()) + .map(|(a, u)| a.tracking_id(&u.into())) + .or_else(|| Some(get_device_id())); + user.username = auth; user }); @@ -126,11 +133,13 @@ fn initialize_sentry(dsn: &str) { // the safe side, make sure we blow up panic!("in the disco"); } + + sentry::configure_scope(|scope| scope.set_user(Some(sentry_user()))); } fn sentry_user() -> sentry::User { sentry::User { - id: Some(get_device_id()), + other: [("device_id".to_string(), get_device_id().into())].into(), ..Default::default() } } diff --git a/client/src/utils/services.ts b/client/src/utils/services.ts index 2aff82eae6..5c7c8fac0b 100644 --- a/client/src/utils/services.ts +++ b/client/src/utils/services.ts @@ -34,7 +34,8 @@ export const initializeSentry = (envConfig: EnvConfig, release: string) => { }); Sentry.setUser({ - id: envConfig.device_id, + id: envConfig.tracking_id, username: envConfig.user_login, + device_id: envConfig.device_id, }); }; diff --git a/server/bleep/src/lib.rs b/server/bleep/src/lib.rs index 8a6482545f..0517dbc0fe 100644 --- a/server/bleep/src/lib.rs +++ b/server/bleep/src/lib.rs @@ -92,7 +92,7 @@ pub struct Application { cookie_key: axum_extra::extract::cookie::Key, /// Analytics backend -- may be unintialized - analytics: Option>, + pub analytics: Option>, } impl Application { diff --git a/server/bleep/src/state.rs b/server/bleep/src/state.rs index d4ba0369f8..9beecef654 100644 --- a/server/bleep/src/state.rs +++ b/server/bleep/src/state.rs @@ -65,10 +65,13 @@ impl PersistedState fn load_or(name: &'static str, source: &StateSource, val: T) -> Self { let path = source.directory().join(name).with_extension("json"); - Self { + let new = Self { state: Arc::new(read_file(&path).unwrap_or(val)), path, - } + }; + + new.store().unwrap(); + new } pub fn store(&self) -> Result<()> { diff --git a/server/bleep/src/webserver/middleware.rs b/server/bleep/src/webserver/middleware.rs index e25781a1a8..41e2fda749 100644 --- a/server/bleep/src/webserver/middleware.rs +++ b/server/bleep/src/webserver/middleware.rs @@ -12,6 +12,12 @@ use sentry::{Hub, SentryFutureExt}; #[derive(Clone)] pub struct User(pub Option); +impl From for User { + fn from(value: String) -> Self { + User(Some(value)) + } +} + pub fn sentry_layer(router: Router) -> Router { router.layer(from_fn(sentry_layer_mw)) }