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
16use std::collections::HashMap;
17
18pub use builder::Builder;
19pub use identity::{AnonymousDistinctId, DeviceId, DistinctId};
20pub use recorder::Recorder;
21pub use worker::Worker;
22
23pub type Map = serde_json::Map<String, serde_json::Value>;
24pub type Groups = HashMap<String, String>;
25
26#[macro_export]
27macro_rules! builder {
28    () => {{
29        let builder = detsys_ids_client::Builder::new()
30            .fact("cargo_pkg_name", env!("CARGO_PKG_NAME"))
31            .fact("$app_version", env!("CARGO_PKG_VERSION"))
32            .fact("$app_name", env!("CARGO_CRATE_NAME"))
33            .enable_reporting(detsys_ids_client::is_telemetry_enabled())
34            .endpoint(detsys_ids_client::get_ambient_transport_endpoint());
35
36        builder
37    }};
38}
39
40pub fn is_telemetry_enabled() -> bool {
41    let enabled = std::env::var_os("DETSYS_IDS_TELEMETRY").as_deref()
42        != Some(std::ffi::OsStr::new("disabled"));
43
44    if !enabled {
45        eprintln!(
46            "{}",
47            [
48                "[NOTE] Telemetry is disabled, which makes it harder to build great software.",
49                "We don't collect much, so please turn it back on:",
50                "https://dtr.mn/telemetry",
51            ]
52            .join(" ")
53        );
54    }
55
56    enabled
57}
58
59pub fn get_ambient_transport_endpoint() -> Option<String> {
60    std::env::var("DETSYS_IDS_TRANSPORT").ok()
61}