Skip to main content

libdd_telemetry/
lib.rs

1// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4#![allow(clippy::mutex_atomic)]
5#![allow(clippy::nonminimal_bool)]
6#![cfg_attr(not(test), deny(clippy::panic))]
7#![cfg_attr(not(test), deny(clippy::unwrap_used))]
8#![cfg_attr(not(test), deny(clippy::expect_used))]
9#![cfg_attr(not(test), deny(clippy::todo))]
10#![cfg_attr(not(test), deny(clippy::unimplemented))]
11
12use libdd_common::entity_id;
13use tracing::debug;
14
15pub mod config;
16pub mod data;
17pub mod info;
18pub mod metrics;
19pub mod worker;
20
21pub use libdd_common::tag::{parse_tags, Tag};
22pub use libdd_common::{parse_uri, Endpoint};
23
24pub fn build_host() -> data::Host {
25    debug!("Building telemetry host information");
26    let hostname = info::os::real_hostname().unwrap_or_else(|_| String::from("unknown_hostname"));
27    let container_id = entity_id::get_container_id().map(|f| f.to_string());
28    let os_version = info::os::os_version().ok();
29
30    debug!(
31        host.hostname = %hostname,
32        host.container_id = ?container_id,
33        host.os = info::os::os_name(),
34        host.os_version = ?os_version,
35        host.architecture = info::os::architecture(),
36        "Built telemetry host information"
37    );
38
39    data::Host {
40        hostname,
41        container_id,
42        os: Some(String::from(info::os::os_name())),
43        os_version,
44        architecture: Some(String::from(info::os::architecture())),
45        kernel_name: info::os::os_type(),
46        kernel_release: info::os::os_release(),
47        #[cfg(unix)]
48        kernel_version: unsafe { info::os::uname() },
49        #[cfg(windows)]
50        kernel_version: winver::WindowsVersion::detect()
51            .map(|wv| format!("{}.{}.{}", wv.major, wv.minor, wv.build)),
52        #[cfg(not(any(windows, unix)))]
53        kernel_version: None,
54    }
55}