@@ -5,10 +5,13 @@ use feature_probe_event::event::AccessEvent;
55use feature_probe_event:: recorder:: { unix_timestamp, EventRecorder } ;
66use parking_lot:: RwLock ;
77use serde_json:: Value ;
8+ use std:: env;
89use std:: sync:: Arc ;
910use std:: time:: Duration ;
1011use url:: Url ;
1112
13+ const VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
14+
1215#[ derive( Debug , Clone ) ]
1316pub 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) ]
183202mod tests {
184203 use serde_json:: json;
0 commit comments