Skip to main content

detsys_ids_client/
lib.rs

1mod builder;
2pub mod checkin;
3mod collator;
4mod compression_set;
5mod configuration_proxy;
6mod ds_correlation;
7mod identity;
8mod json_string;
9mod recorder;
10pub mod storage;
11mod submitter;
12pub mod system_snapshot;
13pub mod transport;
14mod worker;
15
16#[cfg(test)]
17mod test;
18
19use std::collections::HashMap;
20
21pub use builder::Builder;
22pub use identity::{AnonymousDistinctId, DeviceId, DistinctId};
23pub use recorder::{IdentifyProperties, Recorder};
24pub use worker::Worker;
25
26pub type Map = serde_json::Map<String, serde_json::Value>;
27pub type Groups = HashMap<String, String>;
28pub type PersonProperties = Map;
29
30#[macro_export]
31macro_rules! builder {
32    () => {{
33        let builder = detsys_ids_client::Builder::new()
34            .fact("cargo_pkg_name", env!("CARGO_PKG_NAME"))
35            .fact("$app_version", env!("CARGO_PKG_VERSION"))
36            .fact("$app_name", env!("CARGO_CRATE_NAME"))
37            .enable_reporting(detsys_ids_client::is_telemetry_enabled())
38            .endpoint(detsys_ids_client::get_ambient_transport_endpoint());
39
40        builder
41    }};
42}
43
44pub fn is_telemetry_enabled() -> bool {
45    let enabled = std::env::var_os("DETSYS_IDS_TELEMETRY").as_deref()
46        != Some(std::ffi::OsStr::new("disabled"));
47
48    if !enabled {
49        eprintln!(
50            "{}",
51            [
52                "[NOTE] Telemetry is disabled, which makes it harder to build great software.",
53                "We don't collect much, so please turn it back on:",
54                "https://dtr.mn/telemetry",
55            ]
56            .join(" ")
57        );
58    }
59
60    enabled
61}
62
63pub fn get_ambient_transport_endpoint() -> Option<String> {
64    std::env::var("DETSYS_IDS_TRANSPORT").ok()
65}