Skip to content

Commit 2762127

Browse files
committed
feat: user-agent
1 parent c3b9661 commit 2762127

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "feature_probe_mobile_sdk_core"
4-
version = "1.0.1"
4+
version = "1.0.2"
55

66
[lib]
77
name = "feature_probe_mobile_sdk_core"
@@ -34,7 +34,7 @@ tokio = { version = "1", features = ["full"] }
3434
tracing = "0.1"
3535
url = "2"
3636

37-
feature-probe-event = { version = "1.0.1", features = ["use_tokio"], default-features = false }
37+
feature-probe-event = { version = "1.0.4", features = ["use_tokio"], default-features = false }
3838

3939
[dev-dependencies]
4040
approx = "0.5"

rust-core/src/feature_probe.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use feature_probe_event::event::AccessEvent;
55
use feature_probe_event::recorder::{unix_timestamp, EventRecorder};
66
use parking_lot::RwLock;
77
use serde_json::Value;
8+
use std::env;
89
use std::sync::Arc;
910
use std::time::Duration;
1011
use url::Url;
1112

13+
const VERSION: &str = env!("CARGO_PKG_VERSION");
14+
1215
#[derive(Debug, Clone)]
1316
pub struct FeatureProbe {
1417
repo: Arc<RwLock<Repository>>,
@@ -117,20 +120,19 @@ impl FeatureProbe {
117120
None => FPDetail {
118121
value: default,
119122
reason: format!("Toggle {} not found", toggle),
120-
rule_index: None,
121-
version: None,
123+
..Default::default()
122124
},
123125
Some(d) => match transform(&d.value) {
124126
None => FPDetail {
125127
value: default,
126128
reason: "Value type mismatch".to_owned(),
127-
rule_index: None,
128-
version: None,
129+
..Default::default()
129130
},
130131
Some(v) => FPDetail {
131132
value: v,
132133
reason: d.reason.clone(),
133134
rule_index: d.rule_index,
135+
variation_index: d.variation_index,
134136
version: d.version,
135137
},
136138
},
@@ -145,7 +147,7 @@ impl FeatureProbe {
145147
time: unix_timestamp(),
146148
key: toggle.to_owned(),
147149
value: value.clone(),
148-
index: detail.rule_index,
150+
index: detail.variation_index,
149151
version: detail.version,
150152
reason: detail.reason.clone(),
151153
});
@@ -174,11 +176,28 @@ impl FeatureProbe {
174176
let events_url = self.config.events_url.clone();
175177
let flush_interval = self.config.refresh_interval;
176178
let auth = SdkAuthorization(self.config.client_sdk_key.clone()).encode();
177-
let event_recorder = EventRecorder::new(events_url, auth, flush_interval, 100);
179+
let event_recorder =
180+
EventRecorder::new(events_url, auth, user_agent(), flush_interval, 100);
181+
178182
self.event_recorder = Some(event_recorder);
179183
}
180184
}
181185

186+
fn user_agent() -> String {
187+
let mut target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or("uniffi".to_owned());
188+
189+
if target_os.is_empty() {
190+
target_os = "uniffi".to_owned();
191+
}
192+
193+
if &target_os == "ios" {
194+
target_os = "iOS".to_owned();
195+
} else {
196+
target_os = target_os[0..1].to_uppercase() + &target_os[1..];
197+
}
198+
format!("{}/{}", target_os, VERSION)
199+
}
200+
182201
#[cfg(test)]
183202
mod tests {
184203
use serde_json::json;

rust-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub type Repository = HashMap<String, FPDetail<Value>>;
2020
pub struct FPDetail<T: Default> {
2121
pub value: T,
2222
pub rule_index: Option<usize>,
23+
pub variation_index: Option<usize>,
2324
pub version: Option<u64>,
2425
pub reason: String,
2526
}

0 commit comments

Comments
 (0)