glean_preview/
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 glean_core::{metrics::StringMetric, CommonMetricData, Lifetime};
6
7/// Metrics included in every ping as `client_info`.
8#[derive(Debug)]
9pub struct ClientInfoMetrics {
10    /// The build identifier generated by the CI system (e.g. "1234/A").
11    pub app_build: String,
12    /// The user visible version string (e.g. "1.0.3").
13    pub app_display_version: String,
14}
15
16impl ClientInfoMetrics {
17    /// Create the client info with dummy values for all.
18    pub fn unknown() -> Self {
19        ClientInfoMetrics {
20            app_build: "unknown".to_string(),
21            app_display_version: "unknown".to_string(),
22        }
23    }
24}
25
26#[derive(Debug)]
27pub struct InternalMetrics {
28    pub app_build: StringMetric,
29    pub app_display_version: StringMetric,
30    pub app_channel: StringMetric,
31    pub os: StringMetric,
32    pub os_version: StringMetric,
33    pub architecture: StringMetric,
34    pub device_manufacturer: StringMetric,
35    pub device_model: StringMetric,
36}
37
38impl InternalMetrics {
39    pub fn new() -> Self {
40        Self {
41            app_build: StringMetric::new(CommonMetricData {
42                name: "app_build".into(),
43                category: "".into(),
44                send_in_pings: vec!["glean_client_info".into()],
45                lifetime: Lifetime::Application,
46                disabled: false,
47                dynamic_label: None,
48            }),
49            app_display_version: StringMetric::new(CommonMetricData {
50                name: "app_display_version".into(),
51                category: "".into(),
52                send_in_pings: vec!["glean_client_info".into()],
53                lifetime: Lifetime::Application,
54                disabled: false,
55                dynamic_label: None,
56            }),
57            app_channel: StringMetric::new(CommonMetricData {
58                name: "app_channel".into(),
59                category: "".into(),
60                send_in_pings: vec!["glean_client_info".into()],
61                lifetime: Lifetime::Application,
62                disabled: false,
63                dynamic_label: None,
64            }),
65            os: StringMetric::new(CommonMetricData {
66                name: "os".into(),
67                category: "".into(),
68                send_in_pings: vec!["glean_client_info".into()],
69                lifetime: Lifetime::Application,
70                disabled: false,
71                dynamic_label: None,
72            }),
73            os_version: StringMetric::new(CommonMetricData {
74                name: "os_version".into(),
75                category: "".into(),
76                send_in_pings: vec!["glean_client_info".into()],
77                lifetime: Lifetime::Application,
78                disabled: false,
79                dynamic_label: None,
80            }),
81            architecture: StringMetric::new(CommonMetricData {
82                name: "architecture".into(),
83                category: "".into(),
84                send_in_pings: vec!["glean_client_info".into()],
85                lifetime: Lifetime::Application,
86                disabled: false,
87                dynamic_label: None,
88            }),
89            device_manufacturer: 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                dynamic_label: None,
96            }),
97            device_model: StringMetric::new(CommonMetricData {
98                name: "device_model".into(),
99                category: "".into(),
100                send_in_pings: vec!["glean_client_info".into()],
101                lifetime: Lifetime::Application,
102                disabled: false,
103                dynamic_label: None,
104            }),
105        }
106    }
107}