glean_core/
core_metrics.rs

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
5use crate::metrics::{
6    Datetime, DatetimeMetric, QuantityMetric, StringMetric, TimeUnit, TimespanMetric,
7};
8use crate::{CommonMetricData, Lifetime};
9
10use once_cell::sync::Lazy;
11
12/// Metrics included in every ping as `client_info`.
13#[derive(Debug, Default)]
14pub struct ClientInfoMetrics {
15    /// The build identifier generated by the CI system (e.g. "1234/A").
16    pub app_build: String,
17    /// The user visible version string (e.g. "1.0.3").
18    pub app_display_version: String,
19    /// The app's build date
20    pub app_build_date: Datetime,
21
22    /// The architecture of the device (e.g. "arm", "x86").
23    pub architecture: String,
24    /// The name of the operating system (e.g. "Linux", "Android", "iOS").
25    pub os_version: String,
26
27    /// The product-provided release channel (e.g. "beta").
28    pub channel: Option<String>,
29    /// The Android specific SDK version of the software running on this hardware device (e.g. "23").
30    pub android_sdk_version: Option<String>,
31    /// The Windows specific OS build version (e.g. 19043)
32    pub windows_build_number: Option<i64>,
33    /// The manufacturer of the device the application is running on.
34    /// Not set if the device manufacturer can't be determined (e.g. on Desktop).
35    pub device_manufacturer: Option<String>,
36    /// The model of the device the application is running on.
37    /// On Android, this is Build.MODEL, the user-visible marketing name, like "Pixel 2 XL".
38    /// Not set if the device model can't be determined (e.g. on Desktop).
39    pub device_model: Option<String>,
40    /// The locale of the application during initialization (e.g. "es-ES").
41    /// If the locale can't be determined on the system, the value is "und", to indicate "undetermined".
42    pub locale: Option<String>,
43}
44
45/// Metrics included in every ping as `client_info`.
46impl ClientInfoMetrics {
47    /// Creates the client info with dummy values for all.
48    pub fn unknown() -> Self {
49        ClientInfoMetrics {
50            app_build: "Unknown".to_string(),
51            app_display_version: "Unknown".to_string(),
52            app_build_date: Datetime::default(),
53            architecture: "Unknown".to_string(),
54            os_version: "Unknown".to_string(),
55            channel: Some("Unknown".to_string()),
56            android_sdk_version: None,
57            windows_build_number: None,
58            device_manufacturer: None,
59            device_model: None,
60            locale: None,
61        }
62    }
63}
64
65#[allow(non_upper_case_globals)]
66pub mod internal_metrics {
67    use super::*;
68
69    pub static app_build: Lazy<StringMetric> = Lazy::new(|| {
70        StringMetric::new(CommonMetricData {
71            name: "app_build".into(),
72            category: "".into(),
73            send_in_pings: vec!["glean_client_info".into()],
74            lifetime: Lifetime::Application,
75            disabled: false,
76            ..Default::default()
77        })
78    });
79
80    pub static app_display_version: Lazy<StringMetric> = Lazy::new(|| {
81        StringMetric::new(CommonMetricData {
82            name: "app_display_version".into(),
83            category: "".into(),
84            send_in_pings: vec!["glean_client_info".into()],
85            lifetime: Lifetime::Application,
86            disabled: false,
87            ..Default::default()
88        })
89    });
90
91    pub static app_build_date: Lazy<DatetimeMetric> = Lazy::new(|| {
92        DatetimeMetric::new(
93            CommonMetricData {
94                name: "build_date".into(),
95                category: "".into(),
96                send_in_pings: vec!["glean_client_info".into()],
97                lifetime: Lifetime::Application,
98                disabled: false,
99                ..Default::default()
100            },
101            TimeUnit::Second,
102        )
103    });
104
105    pub static app_channel: Lazy<StringMetric> = Lazy::new(|| {
106        StringMetric::new(CommonMetricData {
107            name: "app_channel".into(),
108            category: "".into(),
109            send_in_pings: vec!["glean_client_info".into()],
110            lifetime: Lifetime::Application,
111            disabled: false,
112            ..Default::default()
113        })
114    });
115
116    pub static os_version: Lazy<StringMetric> = Lazy::new(|| {
117        StringMetric::new(CommonMetricData {
118            name: "os_version".into(),
119            category: "".into(),
120            send_in_pings: vec!["glean_client_info".into()],
121            lifetime: Lifetime::Application,
122            disabled: false,
123            ..Default::default()
124        })
125    });
126
127    pub static architecture: Lazy<StringMetric> = Lazy::new(|| {
128        StringMetric::new(CommonMetricData {
129            name: "architecture".into(),
130            category: "".into(),
131            send_in_pings: vec!["glean_client_info".into()],
132            lifetime: Lifetime::Application,
133            disabled: false,
134            ..Default::default()
135        })
136    });
137
138    pub static android_sdk_version: Lazy<StringMetric> = Lazy::new(|| {
139        StringMetric::new(CommonMetricData {
140            name: "android_sdk_version".into(),
141            category: "".into(),
142            send_in_pings: vec!["glean_client_info".into()],
143            lifetime: Lifetime::Application,
144            disabled: false,
145            ..Default::default()
146        })
147    });
148
149    pub static windows_build_number: Lazy<QuantityMetric> = Lazy::new(|| {
150        QuantityMetric::new(CommonMetricData {
151            name: "windows_build_number".into(),
152            category: "".into(),
153            send_in_pings: vec!["glean_client_info".into()],
154            lifetime: Lifetime::Application,
155            disabled: false,
156            ..Default::default()
157        })
158    });
159
160    pub static device_manufacturer: Lazy<StringMetric> = Lazy::new(|| {
161        StringMetric::new(CommonMetricData {
162            name: "device_manufacturer".into(),
163            category: "".into(),
164            send_in_pings: vec!["glean_client_info".into()],
165            lifetime: Lifetime::Application,
166            disabled: false,
167            ..Default::default()
168        })
169    });
170
171    pub static device_model: Lazy<StringMetric> = Lazy::new(|| {
172        StringMetric::new(CommonMetricData {
173            name: "device_model".into(),
174            category: "".into(),
175            send_in_pings: vec!["glean_client_info".into()],
176            lifetime: Lifetime::Application,
177            disabled: false,
178            ..Default::default()
179        })
180    });
181
182    pub static locale: Lazy<StringMetric> = Lazy::new(|| {
183        StringMetric::new(CommonMetricData {
184            name: "locale".into(),
185            category: "".into(),
186            send_in_pings: vec!["glean_client_info".into()],
187            lifetime: Lifetime::Application,
188            disabled: false,
189            ..Default::default()
190        })
191    });
192
193    pub static baseline_duration: Lazy<TimespanMetric> = Lazy::new(|| {
194        TimespanMetric::new(
195            CommonMetricData {
196                name: "duration".into(),
197                category: "glean.baseline".into(),
198                send_in_pings: vec!["baseline".into()],
199                lifetime: Lifetime::Ping,
200                disabled: false,
201                ..Default::default()
202            },
203            TimeUnit::Second,
204        )
205    });
206}