1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 
5 use crate::private::{StringMetric, TimespanMetric};
6 use crate::{CommonMetricData, Lifetime, TimeUnit};
7 
8 use once_cell::sync::Lazy;
9 
10 /// Metrics included in every ping as `client_info`.
11 #[derive(Debug)]
12 pub struct ClientInfoMetrics {
13     /// The build identifier generated by the CI system (e.g. "1234/A").
14     pub app_build: String,
15     /// The user visible version string (e.g. "1.0.3").
16     pub app_display_version: String,
17 }
18 
19 impl ClientInfoMetrics {
20     /// Creates the client info with dummy values for all.
unknown() -> Self21     pub fn unknown() -> Self {
22         ClientInfoMetrics {
23             app_build: "unknown".to_string(),
24             app_display_version: "unknown".to_string(),
25         }
26     }
27 }
28 
29 #[allow(non_upper_case_globals)]
30 pub mod internal_metrics {
31     use super::*;
32 
33     pub static app_build: Lazy<StringMetric> = Lazy::new(|| {
34         StringMetric::new(CommonMetricData {
35             name: "app_build".into(),
36             category: "".into(),
37             send_in_pings: vec!["glean_client_info".into()],
38             lifetime: Lifetime::Application,
39             disabled: false,
40             ..Default::default()
41         })
42     });
43 
44     pub static app_display_version: Lazy<StringMetric> = Lazy::new(|| {
45         StringMetric::new(CommonMetricData {
46             name: "app_display_version".into(),
47             category: "".into(),
48             send_in_pings: vec!["glean_client_info".into()],
49             lifetime: Lifetime::Application,
50             disabled: false,
51             ..Default::default()
52         })
53     });
54 
55     pub static app_channel: Lazy<StringMetric> = Lazy::new(|| {
56         StringMetric::new(CommonMetricData {
57             name: "app_channel".into(),
58             category: "".into(),
59             send_in_pings: vec!["glean_client_info".into()],
60             lifetime: Lifetime::Application,
61             disabled: false,
62             ..Default::default()
63         })
64     });
65 
66     pub static os_version: Lazy<StringMetric> = Lazy::new(|| {
67         StringMetric::new(CommonMetricData {
68             name: "os_version".into(),
69             category: "".into(),
70             send_in_pings: vec!["glean_client_info".into()],
71             lifetime: Lifetime::Application,
72             disabled: false,
73             ..Default::default()
74         })
75     });
76 
77     pub static architecture: Lazy<StringMetric> = Lazy::new(|| {
78         StringMetric::new(CommonMetricData {
79             name: "architecture".into(),
80             category: "".into(),
81             send_in_pings: vec!["glean_client_info".into()],
82             lifetime: Lifetime::Application,
83             disabled: false,
84             ..Default::default()
85         })
86     });
87 
88     pub static device_manufacturer: Lazy<StringMetric> = Lazy::new(|| {
89         StringMetric::new(CommonMetricData {
90             name: "device_manufacturer".into(),
91             category: "".into(),
92             send_in_pings: vec!["glean_client_info".into()],
93             lifetime: Lifetime::Application,
94             disabled: false,
95             ..Default::default()
96         })
97     });
98 
99     pub static device_model: Lazy<StringMetric> = Lazy::new(|| {
100         StringMetric::new(CommonMetricData {
101             name: "device_model".into(),
102             category: "".into(),
103             send_in_pings: vec!["glean_client_info".into()],
104             lifetime: Lifetime::Application,
105             disabled: false,
106             ..Default::default()
107         })
108     });
109 
110     pub static baseline_duration: Lazy<TimespanMetric> = Lazy::new(|| {
111         TimespanMetric::new(
112             CommonMetricData {
113                 name: "duration".into(),
114                 category: "glean.baseline".into(),
115                 send_in_pings: vec!["baseline".into()],
116                 lifetime: Lifetime::Ping,
117                 disabled: false,
118                 ..Default::default()
119             },
120             TimeUnit::Second,
121         )
122     });
123 }
124