Skip to content

Commit

Permalink
analytics: streamlining host vs. recorder python/rust versions (#1380)
Browse files Browse the repository at this point in the history
* streamline host vs recording python/rust versions

* can't have it all

* just format

* no anonymous strings

* the Rerun CLI does carry a Rust version too

* fmt
  • Loading branch information
teh-cmc authored and emilk committed Mar 2, 2023
1 parent 125ee72 commit 7e0d6ca
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 24 deletions.
5 changes: 5 additions & 0 deletions crates/re_analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ impl Analytics {
self.default_append_props.insert(name.into(), prop.into());
}

/// Deregister a property.
pub fn deregister_append_property(&mut self, name: &'static str) {
self.default_append_props.remove(name);
}

/// Record an event.
///
/// It will be extended with an `event_id` and, if this is an [`EventKind::Append`],
Expand Down
4 changes: 3 additions & 1 deletion crates/re_log_types/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ fn test_encode_decode() {
recording_id: crate::RecordingId::random(),
is_official_example: true,
started: Time::now(),
recording_source: crate::RecordingSource::RustSdk,
recording_source: crate::RecordingSource::RustSdk {
rust_version: env!("CARGO_PKG_RUST_VERSION").into(),
},
},
})];

Expand Down
8 changes: 5 additions & 3 deletions crates/re_log_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl std::fmt::Display for PythonVersion {
patch,
suffix,
} = self;
write!(f, "{}.{}.{}{}", major, minor, patch, suffix)
write!(f, "{major}.{minor}.{patch}{suffix}")
}
}

Expand All @@ -253,7 +253,9 @@ pub enum RecordingSource {
PythonSdk(PythonVersion),

/// The official Rerun Rust Logging SDK
RustSdk,
RustSdk {
rust_version: String,
},

/// Perhaps from some manual data ingestion?
Other(String),
Expand All @@ -264,7 +266,7 @@ impl std::fmt::Display for RecordingSource {
match self {
Self::Unknown => "Unknown".fmt(f),
Self::PythonSdk(version) => write!(f, "Python {version} SDK"),
Self::RustSdk => "Rust SDK".fmt(f),
Self::RustSdk { rust_version } => write!(f, "Rust {rust_version} SDK"),
Self::Other(string) => format!("{string:?}").fmt(f), // put it in quotes
}
}
Expand Down
13 changes: 10 additions & 3 deletions crates/re_sdk/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ impl Session {
Self {
enabled,

recording_source: RecordingSource::RustSdk,
recording_source: RecordingSource::RustSdk {
rust_version: env!("CARGO_PKG_RUST_VERSION").into(),
},

#[cfg(feature = "web")]
tokio_rt: tokio::runtime::Runtime::new().unwrap(),
Expand Down Expand Up @@ -399,8 +401,13 @@ impl Session {
RecordingSource::PythonSdk(python_version) => {
re_viewer::AppEnvironment::PythonSdk(python_version.clone())
}
RecordingSource::Unknown | RecordingSource::RustSdk | RecordingSource::Other(_) => {
re_viewer::AppEnvironment::RustSdk
RecordingSource::RustSdk { rust_version } => re_viewer::AppEnvironment::RustSdk {
rust_version: rust_version.clone(),
},
RecordingSource::Unknown | RecordingSource::Other(_) => {
re_viewer::AppEnvironment::RustSdk {
rust_version: "unknown".into(),
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ pub enum AppEnvironment {
PythonSdk(PythonVersion),

/// Created from the Rerun Rust SDK.
RustSdk,
RustSdk { rust_version: String },

/// Running the Rust `rerun` binary from the CLI.
RerunCli,
RerunCli { rust_version: String },

/// We are a web-viewer running in a browser as Wasm.
Web,
Expand Down
51 changes: 37 additions & 14 deletions crates/re_viewer/src/viewer_analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ impl ViewerAnalytics {
analytics.register_append_property(name, property);
}
}

/// Deregister a property.
#[cfg(all(not(target_arch = "wasm32"), feature = "analytics"))]
fn deregister(&mut self, name: &'static str) {
if let Some(analytics) = &mut self.analytics {
analytics.deregister_append_property(name);
}
}
}

// ----------------------------------------------------------------------------
Expand All @@ -61,29 +69,39 @@ impl ViewerAnalytics {
use crate::AppEnvironment;
let app_env_str = match app_env {
AppEnvironment::PythonSdk(_) => "python_sdk",
AppEnvironment::RustSdk => "rust_sdk",
AppEnvironment::RerunCli => "rerun_cli",
AppEnvironment::RustSdk { rust_version: _ } => "rust_sdk",
AppEnvironment::RerunCli { rust_version: _ } => "rerun_cli",
AppEnvironment::Web => "web",
};
self.register("app_env", app_env_str.to_owned());

if let AppEnvironment::PythonSdk(version) = app_env {
self.register("python_version", version.to_string());
}

#[cfg(all(not(target_arch = "wasm32"), feature = "analytics"))]
if let Some(analytics) = &self.analytics {
let rerun_version = env!("CARGO_PKG_VERSION");
let rust_version = env!("CARGO_PKG_RUST_VERSION");
let target = re_analytics::TARGET_TRIPLET;
let git_hash = re_analytics::GIT_HASH;

let mut event = Event::update("update_metadata".into())
.with_prop("rerun_version".into(), rerun_version.to_owned())
.with_prop("rust_version".into(), rust_version.to_owned())
.with_prop("target".into(), target.to_owned())
.with_prop("git_hash".into(), git_hash.to_owned());

// If we happen to know the Python or Rust version used on the _host machine_, i.e. the
// machine running the viewer, then add it to the permanent user profile.
//
// The Python/Rust versions appearing in user profiles always apply to the host
// environment, _not_ the environment in which the data logging is taking place!
match &app_env {
AppEnvironment::RustSdk { rust_version }
| AppEnvironment::RerunCli { rust_version } => {
event = event.with_prop("rust_version".into(), rust_version.clone());
}
_ => {}
}
if let AppEnvironment::PythonSdk(version) = app_env {
event = event.with_prop("python_version".into(), version.to_string());
}

// Append opt-in metadata.
// In practice this is the email of Rerun employees
// who register their emails with `rerun analytics email`.
Expand Down Expand Up @@ -124,17 +142,22 @@ impl ViewerAnalytics {
let recording_source = match &rec_info.recording_source {
RecordingSource::Unknown => "unknown".to_owned(),
RecordingSource::PythonSdk(_version) => "python_sdk".to_owned(),
RecordingSource::RustSdk => "rust_sdk".to_owned(),
RecordingSource::RustSdk { rust_version: _ } => "rust_sdk".to_owned(),
RecordingSource::Other(other) => other.clone(),
};

// If we happen to know the Python or Rust version used on the _recording machine_,
// then append it to all future events.
//
// The Python/Rust versions appearing in events always apply to the recording
// environment, _not_ the environment in which the viewer is running!
if let RecordingSource::RustSdk { rust_version } = &rec_info.recording_source {
self.register("rust_version", rust_version.to_string());
self.deregister("python_version"); // can't be both!
}
if let RecordingSource::PythonSdk(version) = &rec_info.recording_source {
// This will over-write what is set by `AppEnvironment`, if any.
// Usually these would be the same, but if you are using one python version to look
// at a recording from an older python version, then they will differ.
// For simplicity's sake we ignore this. We just want a rough idea of
// what python version our users use.
self.register("python_version", version.to_string());
self.deregister("rust_version"); // can't be both!
}

self.register("recording_source", recording_source);
Expand Down
4 changes: 3 additions & 1 deletion crates/rerun/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ impl CallSource {

fn app_env(&self) -> re_viewer::AppEnvironment {
match self {
CallSource::Cli => re_viewer::AppEnvironment::RerunCli,
CallSource::Cli => re_viewer::AppEnvironment::RerunCli {
rust_version: env!("CARGO_PKG_RUST_VERSION").into(),
},
CallSource::Python(python_version) => {
re_viewer::AppEnvironment::PythonSdk(python_version.clone())
}
Expand Down

0 comments on commit 7e0d6ca

Please sign in to comment.