Skip to content

Commit

Permalink
Use uniform rudderstack & sentry tracking references (#621)
Browse files Browse the repository at this point in the history
* Use uniform rudderstack & sentry tracking references

* Fall back to device id if user is not available

* Change on frontend

* Make sure we store the defaults
  • Loading branch information
rsdy authored Jun 9, 2023
1 parent 82049e4 commit b9563ab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
13 changes: 11 additions & 2 deletions apps/desktop/src-tauri/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down Expand Up @@ -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()
}
}
Expand Down
3 changes: 2 additions & 1 deletion client/src/utils/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};
2 changes: 1 addition & 1 deletion server/bleep/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub struct Application {
cookie_key: axum_extra::extract::cookie::Key,

/// Analytics backend -- may be unintialized
analytics: Option<Arc<analytics::RudderHub>>,
pub analytics: Option<Arc<analytics::RudderHub>>,
}

impl Application {
Expand Down
7 changes: 5 additions & 2 deletions server/bleep/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ impl<T: Serialize + DeserializeOwned + Default + Send + Sync> PersistedState<T>

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<()> {
Expand Down
6 changes: 6 additions & 0 deletions server/bleep/src/webserver/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use sentry::{Hub, SentryFutureExt};
#[derive(Clone)]
pub struct User(pub Option<String>);

impl From<String> for User {
fn from(value: String) -> Self {
User(Some(value))
}
}

pub fn sentry_layer(router: Router) -> Router {
router.layer(from_fn(sentry_layer_mw))
}
Expand Down

0 comments on commit b9563ab

Please sign in to comment.