diff --git a/Cargo.lock b/Cargo.lock index 2570e6b..cd8e56e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -448,7 +448,7 @@ dependencies = [ "dogstatsd", "figment", "libdd-trace-obfuscation", - "libdd-trace-utils 3.0.1", + "libdd-trace-utils 6.0.1", "log", "serde", "serde-aux", @@ -492,7 +492,7 @@ name = "datadog-metrics-collector" version = "0.1.0" dependencies = [ "dogstatsd", - "libdd-common 4.0.0", + "libdd-common 4.2.0", "tokio", "tracing", "windows-sys 0.61.2", @@ -514,7 +514,7 @@ dependencies = [ "libdd-common 2.0.1", "libdd-data-pipeline", "libdd-telemetry", - "libdd-tinybytes 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libdd-tinybytes 1.1.0", "libdd-trace-utils 2.0.2", "lru", "opentelemetry", @@ -554,7 +554,7 @@ dependencies = [ "datadog-metrics-collector", "datadog-trace-agent", "dogstatsd", - "libdd-trace-utils 3.0.1", + "libdd-trace-utils 6.0.1", "reqwest", "serde_json", "tokio", @@ -580,12 +580,12 @@ dependencies = [ "hyper-util", "libdd-capabilities", "libdd-capabilities-impl", - "libdd-common 4.0.0", + "libdd-common 4.2.0", "libdd-library-config", "libdd-trace-obfuscation", - "libdd-trace-protobuf 3.0.1", - "libdd-trace-stats 2.0.0", - "libdd-trace-utils 3.0.1", + "libdd-trace-protobuf 3.0.2", + "libdd-trace-stats 4.0.0", + "libdd-trace-utils 6.0.1", "reqwest", "rmp-serde", "serde", @@ -1446,8 +1446,8 @@ checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" [[package]] name = "libdd-capabilities" -version = "1.0.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "2.0.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", "bytes", @@ -1457,14 +1457,14 @@ dependencies = [ [[package]] name = "libdd-capabilities-impl" -version = "1.0.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "2.0.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "bytes", "http", "http-body-util", "libdd-capabilities", - "libdd-common 4.0.0", + "libdd-common 4.2.0", "tokio", ] @@ -1501,8 +1501,8 @@ dependencies = [ [[package]] name = "libdd-common" -version = "4.0.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "4.2.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", "bytes", @@ -1549,7 +1549,7 @@ dependencies = [ "libdd-ddsketch 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "libdd-dogstatsd-client", "libdd-telemetry", - "libdd-tinybytes 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libdd-tinybytes 1.1.0", "libdd-trace-protobuf 2.0.0", "libdd-trace-stats 1.0.3", "libdd-trace-utils 2.0.2", @@ -1575,7 +1575,7 @@ dependencies = [ [[package]] name = "libdd-ddsketch" version = "1.0.1" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "prost 0.14.3", ] @@ -1596,12 +1596,12 @@ dependencies = [ [[package]] name = "libdd-library-config" -version = "1.1.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "2.0.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", "libc", - "libdd-trace-protobuf 3.0.1", + "libdd-trace-protobuf 3.0.2", "memfd", "prost 0.14.3", "rand 0.8.6", @@ -1613,15 +1613,15 @@ dependencies = [ [[package]] name = "libdd-shared-runtime" -version = "0.1.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "1.0.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "async-trait", "futures", "futures-util", "libdd-capabilities", "libdd-capabilities-impl", - "libdd-common 4.0.0", + "libdd-common 4.2.0", "tokio", "tokio-util", "tracing", @@ -1664,8 +1664,8 @@ dependencies = [ [[package]] name = "libdd-tinybytes" -version = "1.1.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "1.1.1" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "serde", ] @@ -1683,22 +1683,22 @@ dependencies = [ [[package]] name = "libdd-trace-normalization" version = "2.0.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", - "libdd-trace-protobuf 3.0.1", + "libdd-trace-protobuf 3.0.2", ] [[package]] name = "libdd-trace-obfuscation" -version = "2.0.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "3.1.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", "fluent-uri", - "libdd-common 4.0.0", - "libdd-trace-protobuf 3.0.1", - "libdd-trace-utils 3.0.1", + "libdd-common 4.2.0", + "libdd-trace-protobuf 3.0.2", + "libdd-trace-utils 6.0.1", "log", "percent-encoding", "serde", @@ -1718,8 +1718,8 @@ dependencies = [ [[package]] name = "libdd-trace-protobuf" -version = "3.0.1" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "3.0.2" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "prost 0.14.3", "serde", @@ -1740,8 +1740,8 @@ dependencies = [ [[package]] name = "libdd-trace-stats" -version = "2.0.0" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "4.0.0" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", "arc-swap", @@ -1750,12 +1750,12 @@ dependencies = [ "http", "libdd-capabilities", "libdd-capabilities-impl", - "libdd-common 4.0.0", - "libdd-ddsketch 1.0.1 (git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81)", + "libdd-common 4.2.0", + "libdd-ddsketch 1.0.1 (git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767)", "libdd-shared-runtime", "libdd-trace-obfuscation", - "libdd-trace-protobuf 3.0.1", - "libdd-trace-utils 3.0.1", + "libdd-trace-protobuf 3.0.2", + "libdd-trace-utils 6.0.1", "rmp-serde", "serde", "tokio", @@ -1777,7 +1777,7 @@ dependencies = [ "http-body-util", "indexmap", "libdd-common 2.0.1", - "libdd-tinybytes 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libdd-tinybytes 1.1.0", "libdd-trace-normalization 1.0.2", "libdd-trace-protobuf 2.0.0", "prost 0.14.3", @@ -1793,8 +1793,8 @@ dependencies = [ [[package]] name = "libdd-trace-utils" -version = "3.0.1" -source = "git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81#0a3304c6aaf84738786b670d706a01edc22dab81" +version = "6.0.1" +source = "git+https://github.com/DataDog/libdatadog?rev=62e9d0148219f89fea3aab066235d9c9ddd43767#62e9d0148219f89fea3aab066235d9c9ddd43767" dependencies = [ "anyhow", "base64 0.22.1", @@ -1812,10 +1812,10 @@ dependencies = [ "indexmap", "libdd-capabilities", "libdd-capabilities-impl", - "libdd-common 4.0.0", - "libdd-tinybytes 1.1.0 (git+https://github.com/DataDog/libdatadog?rev=0a3304c6aaf84738786b670d706a01edc22dab81)", + "libdd-common 4.2.0", + "libdd-tinybytes 1.1.1", "libdd-trace-normalization 2.0.0", - "libdd-trace-protobuf 3.0.1", + "libdd-trace-protobuf 3.0.2", "prost 0.14.3", "rand 0.8.6", "rmp", diff --git a/crates/datadog-agent-config/Cargo.toml b/crates/datadog-agent-config/Cargo.toml index 9238f84..cd659fc 100644 --- a/crates/datadog-agent-config/Cargo.toml +++ b/crates/datadog-agent-config/Cargo.toml @@ -6,8 +6,8 @@ license.workspace = true [dependencies] figment = { version = "0.10", default-features = false, features = ["yaml", "env"] } -libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } +libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } log = { version = "0.4", default-features = false } serde = { version = "1.0", default-features = false, features = ["derive"] } serde-aux = { version = "4.7", default-features = false } diff --git a/crates/datadog-metrics-collector/Cargo.toml b/crates/datadog-metrics-collector/Cargo.toml index bfb06ad..5b1f696 100644 --- a/crates/datadog-metrics-collector/Cargo.toml +++ b/crates/datadog-metrics-collector/Cargo.toml @@ -8,7 +8,7 @@ description = "Collector to read, compute, and submit enhanced metrics in Server [dependencies] dogstatsd = { path = "../dogstatsd", default-features = true } tracing = { version = "0.1", default-features = false } -libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81", default-features = false } +libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767", default-features = false } [target.'cfg(windows)'.dependencies] windows-sys = { version = "0.61", features = ["Win32_System_JobObjects"], optional = true, default-features = false } diff --git a/crates/datadog-metrics-collector/src/azure_instance.rs b/crates/datadog-metrics-collector/src/azure_instance.rs index 60e6f3e..22d1b2b 100644 --- a/crates/datadog-metrics-collector/src/azure_instance.rs +++ b/crates/datadog-metrics-collector/src/azure_instance.rs @@ -8,51 +8,11 @@ use dogstatsd::aggregator::AggregatorHandle; use dogstatsd::metric::{Metric, MetricValue, SortedTags}; -use std::env; +use libdd_common::azure_app_services; use tracing::{error, warn}; const INSTANCE_METRIC: &str = "azure.functions.enhanced.instance"; -/// Resolves the instance ID from explicit values (used by tests). -/// -/// Picks the env var that matches the Azure integration metric's `instance` -/// tag for the current hosting plan with fallback logic -/// if the preferred source is empty. -fn resolve_instance_id_from( - website_sku: Option<&str>, - container_name: Option<&str>, - website_pod_name: Option<&str>, - computer_name: Option<&str>, -) -> Option { - fn non_empty(s: Option<&str>) -> Option<&str> { - s.filter(|v| !v.is_empty()) - } - - let sku_preferred = match website_sku { - Some("FlexConsumption") | Some("Dynamic") => { - non_empty(container_name).or(non_empty(website_pod_name)) - } - Some(_) => non_empty(computer_name), - None => None, - }; - - sku_preferred - .or_else(|| non_empty(container_name)) - .or_else(|| non_empty(website_pod_name)) - .or_else(|| non_empty(computer_name)) - .map(|s| s.to_lowercase()) -} - -/// Resolves the instance ID from environment variables. -fn resolve_instance_id() -> Option { - resolve_instance_id_from( - env::var("WEBSITE_SKU").ok().as_deref(), - env::var("CONTAINER_NAME").ok().as_deref(), - env::var("WEBSITE_POD_NAME").ok().as_deref(), - env::var("COMPUTERNAME").ok().as_deref(), - ) -} - pub struct InstanceMetricsCollector { aggregator: AggregatorHandle, tags: Option, @@ -61,8 +21,12 @@ pub struct InstanceMetricsCollector { impl InstanceMetricsCollector { /// Creates a new collector, returning `None` if no instance ID is found. pub fn new(aggregator: AggregatorHandle, tags: Option) -> Option { - let instance_id = resolve_instance_id(); - let Some(instance_id) = instance_id else { + let instance_name = azure_app_services::AAS_METADATA_FUNCTION + .as_ref() + .map(|m| m.get_instance_name().to_owned()) + .filter(|n| n != azure_app_services::UNKNOWN_VALUE); + + let Some(instance_id) = instance_name else { warn!("No instance ID found, instance metric will not be submitted"); return None; }; @@ -95,82 +59,3 @@ impl InstanceMetricsCollector { } } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_flex_consumption_uses_container_name() { - let id = resolve_instance_id_from( - Some("FlexConsumption"), - Some("0--abc-DEF"), - Some("0--abc-DEF"), - None, - ); - assert_eq!(id, Some("0--abc-def".to_string())); - } - - #[test] - fn test_flex_consumption_falls_back_to_pod_name_if_container_missing() { - let id = resolve_instance_id_from(Some("FlexConsumption"), None, Some("pod-XYZ"), None); - assert_eq!(id, Some("pod-xyz".to_string())); - } - - #[test] - fn test_consumption_uses_container_name() { - let id = resolve_instance_id_from( - Some("Dynamic"), - Some("ABCD1234-111122223333444455"), - None, - None, - ); - assert_eq!(id, Some("abcd1234-111122223333444455".to_string())); - } - - #[test] - fn test_elastic_premium_uses_computer_name() { - let id = - resolve_instance_id_from(Some("ElasticPremium"), None, None, Some("ep0fakewk0000A1")); - assert_eq!(id, Some("ep0fakewk0000a1".to_string())); - } - - #[test] - fn test_dedicated_uses_computer_name() { - let id = resolve_instance_id_from(Some("PremiumV3"), None, None, Some("p3fakewk0000B2")); - assert_eq!(id, Some("p3fakewk0000b2".to_string())); - } - - #[test] - fn test_empty_string_is_treated_as_missing() { - let id = - resolve_instance_id_from(Some("ElasticPremium"), Some(""), Some(""), Some("worker-1")); - assert_eq!(id, Some("worker-1".to_string())); - } - - #[test] - fn test_unknown_sku_falls_back_to_search_order() { - let id = resolve_instance_id_from(Some("SomeNewSku"), Some("container-1"), None, None); - assert_eq!(id, Some("container-1".to_string())); - } - - #[test] - fn test_missing_sku_falls_back_to_search_order() { - let id = resolve_instance_id_from(None, Some("container-1"), None, Some("worker-1")); - assert_eq!(id, Some("container-1".to_string())); - } - - #[test] - fn test_no_env_vars_returns_none() { - let id = resolve_instance_id_from(None, None, None, None); - assert_eq!(id, None); - } - - // On Windows Consumption we've observed CONTAINER_NAME and WEBSITE_POD_NAME - // unset but COMPUTERNAME set - #[test] - fn test_windows_consumption_falls_through_to_computer_name() { - let id = resolve_instance_id_from(Some("Dynamic"), None, None, Some("10-20-30-40")); - assert_eq!(id, Some("10-20-30-40".to_string())); - } -} diff --git a/crates/datadog-metrics-collector/src/azure_tags.rs b/crates/datadog-metrics-collector/src/azure_tags.rs index 7558984..61eeb14 100644 --- a/crates/datadog-metrics-collector/src/azure_tags.rs +++ b/crates/datadog-metrics-collector/src/azure_tags.rs @@ -10,9 +10,6 @@ use libdd_common::{azure_app_services, tag::Tag}; use std::env; use tracing::warn; -/// `libdd_common::azure_app_services` returns this value when the corresponding Azure metadata isn't populated. -const AAS_UNKNOWN_VALUE: &str = "unknown"; - /// Builds the common tags for all enhanced metrics. /// /// Sources: @@ -30,15 +27,15 @@ pub fn build_enhanced_metrics_tags() -> Option { ("subscription_id", aas_metadata.get_subscription_id()), ("name", aas_metadata.get_site_name()), ] { - if value != AAS_UNKNOWN_VALUE { + if value != azure_app_services::UNKNOWN_VALUE { pairs.push((name, value.to_string())); } } } for (tag_name, env_var) in [ - ("region", "REGION_NAME"), - ("plan_tier", "WEBSITE_SKU"), + ("region", azure_app_services::REGION_NAME), + ("plan_tier", azure_app_services::WEBSITE_SKU), ("service", "DD_SERVICE"), ("env", "DD_ENV"), ("version", "DD_VERSION"), diff --git a/crates/datadog-serverless-compat/Cargo.toml b/crates/datadog-serverless-compat/Cargo.toml index 2363234..fe87c54 100644 --- a/crates/datadog-serverless-compat/Cargo.toml +++ b/crates/datadog-serverless-compat/Cargo.toml @@ -14,7 +14,7 @@ windows-enhanced-metrics = ["datadog-metrics-collector/windows-enhanced-metrics" datadog-logs-agent = { path = "../datadog-logs-agent" } datadog-metrics-collector = { path = "../datadog-metrics-collector" } datadog-trace-agent = { path = "../datadog-trace-agent" } -libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } +libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } datadog-fips = { path = "../datadog-fips", default-features = false } dogstatsd = { path = "../dogstatsd", default-features = true } reqwest = { version = "0.12.4", default-features = false } diff --git a/crates/datadog-trace-agent/Cargo.toml b/crates/datadog-trace-agent/Cargo.toml index c583023..82dd1cf 100644 --- a/crates/datadog-trace-agent/Cargo.toml +++ b/crates/datadog-trace-agent/Cargo.toml @@ -25,16 +25,16 @@ tracing = { version = "0.1", default-features = false } serde = { version = "1.0.145", features = ["derive"] } serde_json = "1.0" thiserror = { version = "1.0.58", default-features = false } -libdd-capabilities = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-capabilities-impl = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-trace-stats = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } -libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81", features = [ +libdd-capabilities = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-capabilities-impl = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-library-config = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-trace-stats = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } +libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767", features = [ "mini_agent", ] } -libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81" } +libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767" } datadog-fips = { path = "../datadog-fips" } reqwest = { version = "0.12.23", features = [ "json", @@ -49,6 +49,6 @@ serial_test = "2.0.0" duplicate = "2.0.1" temp-env = "0.3.6" tempfile = "3.3.0" -libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "0a3304c6aaf84738786b670d706a01edc22dab81", features = [ +libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "62e9d0148219f89fea3aab066235d9c9ddd43767", features = [ "test-utils", ] } diff --git a/crates/datadog-trace-agent/src/env_verifier.rs b/crates/datadog-trace-agent/src/env_verifier.rs index 9ece700..7ba2fa9 100644 --- a/crates/datadog-trace-agent/src/env_verifier.rs +++ b/crates/datadog-trace-agent/src/env_verifier.rs @@ -4,6 +4,7 @@ use async_trait::async_trait; use http_body_util::BodyExt; use hyper::{Method, Request}; +use libdd_common::azure_app_services; use libdd_common::http_common; use serde::{Deserialize, Serialize}; use std::env; @@ -24,7 +25,6 @@ const AZURE_FUNCTION_JSON_NAME: &str = "function.json"; // Azure environment variables for Flex consumption plan detection const DD_AZURE_RESOURCE_GROUP: &str = "DD_AZURE_RESOURCE_GROUP"; -const WEBSITE_SKU: &str = "WEBSITE_SKU"; #[derive(Default, Debug, Deserialize, Serialize, Eq, PartialEq)] pub struct GCPMetadata { @@ -253,7 +253,7 @@ async fn get_gcp_metadata_from_body(body: http_common::Body) -> anyhow::Result bool { - env::var(WEBSITE_SKU) + env::var(azure_app_services::WEBSITE_SKU) .map(|sku| sku == "FlexConsumption") .unwrap_or(false) && env::var(DD_AZURE_RESOURCE_GROUP).is_err() @@ -370,10 +370,11 @@ mod tests { use crate::env_verifier::{ AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, AzureVerificationClient, AzureVerificationClientWrapper, DD_AZURE_RESOURCE_GROUP, GCPInstance, GCPMetadata, - GCPProject, GoogleMetadataClient, WEBSITE_SKU, ensure_azure_function_environment, + GCPProject, GoogleMetadataClient, ensure_azure_function_environment, ensure_gcp_function_environment, get_region_from_gcp_region_string, is_azure_flex_without_resource_group, }; + use libdd_common::azure_app_services; use super::{EnvVerifier, ServerlessEnvVerifier}; @@ -651,7 +652,7 @@ mod tests { temp_env::with_vars( [ (DD_AZURE_RESOURCE_GROUP, None::<&str>), - (WEBSITE_SKU, Some("FlexConsumption")), + (azure_app_services::WEBSITE_SKU, Some("FlexConsumption")), ], || assert!(is_azure_flex_without_resource_group()), ); @@ -663,7 +664,7 @@ mod tests { temp_env::with_vars( [ (DD_AZURE_RESOURCE_GROUP, Some("test-resource-group")), - (WEBSITE_SKU, Some("FlexConsumption")), + (azure_app_services::WEBSITE_SKU, Some("FlexConsumption")), ], || assert!(!is_azure_flex_without_resource_group()), ); @@ -675,7 +676,7 @@ mod tests { temp_env::with_vars( [ (DD_AZURE_RESOURCE_GROUP, None::<&str>), - (WEBSITE_SKU, Some("ElasticPremium")), + (azure_app_services::WEBSITE_SKU, Some("ElasticPremium")), ], || assert!(!is_azure_flex_without_resource_group()), );