From f61647285b99ba0862a5e3184ee02fda3584f235 Mon Sep 17 00:00:00 2001 From: Kathie Huang Date: Thu, 25 Sep 2025 10:27:59 -0400 Subject: [PATCH 1/6] Shut down trace agent if resource group can't be determined --- .../datadog-trace-agent/src/env_verifier.rs | 107 +++++++++++++++++- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/crates/datadog-trace-agent/src/env_verifier.rs b/crates/datadog-trace-agent/src/env_verifier.rs index 8402e4d..e811526 100644 --- a/crates/datadog-trace-agent/src/env_verifier.rs +++ b/crates/datadog-trace-agent/src/env_verifier.rs @@ -5,6 +5,7 @@ use async_trait::async_trait; use ddcommon::hyper_migration; use http_body_util::BodyExt; use hyper::{Method, Request}; +use regex::Regex; use serde::{Deserialize, Serialize}; use std::env; use std::fs; @@ -22,6 +23,11 @@ const AZURE_WINDOWS_FUNCTION_ROOT_PATH_STR: &str = "C:\\home\\site\\wwwroot"; const AZURE_HOST_JSON_NAME: &str = "host.json"; const AZURE_FUNCTION_JSON_NAME: &str = "function.json"; +// Azure environment variables for resource group detection +const DD_AZURE_RESOURCE_GROUP: &str = "DD_AZURE_RESOURCE_GROUP"; +const WEBSITE_RESOURCE_GROUP: &str = "WEBSITE_RESOURCE_GROUP"; +const WEBSITE_OWNER_NAME: &str = "WEBSITE_OWNER_NAME"; + #[derive(Default, Debug, Deserialize, Serialize, Eq, PartialEq)] pub struct GCPMetadata { pub instance: GCPInstance, @@ -242,6 +248,28 @@ async fn get_gcp_metadata_from_body(body: hyper_migration::Body) -> anyhow::Resu Ok(gcp_metadata) } +/// Determines the Azure resource group using the same logic as libdatadog +/// Returns None if running in Flex consumption plan without DD_AZURE_RESOURCE_GROUP set +fn get_azure_resource_group() -> Option { + env::var(DD_AZURE_RESOURCE_GROUP) + .ok() + .or_else(|| env::var(WEBSITE_RESOURCE_GROUP).ok()) + .or_else(|| extract_resource_group(env::var(WEBSITE_OWNER_NAME).ok())) + .filter(|rg| rg != "flex") +} + +/// Extracts resource group from WEBSITE_OWNER_NAME +/// This uses the exact same regex logic as libdatadog's AzureMetadata::extract_resource_group +fn extract_resource_group(s: Option) -> Option { + #[allow(clippy::unwrap_used)] + let re: Regex = Regex::new(r".+\+(.+)-.+webspace(-Linux)?").unwrap(); + + s.as_ref().and_then(|text| { + re.captures(text) + .and_then(|caps| caps.get(1).map(|m| m.as_str().to_string())) + }) +} + async fn verify_azure_environment_or_exit(os: &str) { let now = Instant::now(); match ensure_azure_function_environment(Box::new(AzureVerificationClientWrapper {}), os).await { @@ -253,6 +281,13 @@ async fn verify_azure_environment_or_exit(os: &str) { process::exit(1); } } + if let None = get_azure_resource_group() { + error!( + "Unable to determine Azure resource group. If you are using Azure Functions on the Flex Consumption plan, \ + please add your resource group name as an environment variable called `DD_AZURE_RESOURCE_GROUP` in Azure App settings." + ); + process::exit(1); + } debug!( "Time taken to verify Azure Functions env: {} ms", now.elapsed().as_millis() @@ -337,13 +372,10 @@ mod tests { use hyper::{body::Bytes, Response, StatusCode}; use serde_json::json; use serial_test::serial; - use std::{fs, path::Path, time::Duration}; + use std::{env, fs, path::Path, time::Duration}; use crate::env_verifier::{ - ensure_azure_function_environment, ensure_gcp_function_environment, - get_region_from_gcp_region_string, AzureVerificationClient, AzureVerificationClientWrapper, - GCPInstance, GCPMetadata, GCPProject, GoogleMetadataClient, AZURE_FUNCTION_JSON_NAME, - AZURE_HOST_JSON_NAME, + ensure_azure_function_environment, ensure_gcp_function_environment, extract_resource_group, get_region_from_gcp_region_string, AzureVerificationClient, AzureVerificationClientWrapper, GCPInstance, GCPMetadata, GCPProject, GoogleMetadataClient, AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, DD_AZURE_RESOURCE_GROUP, WEBSITE_RESOURCE_GROUP, WEBSITE_OWNER_NAME, get_azure_resource_group }; use super::{EnvVerifier, ServerlessEnvVerifier}; @@ -615,4 +647,69 @@ mod tests { assert_eq!(files, vec![AZURE_HOST_JSON_NAME]); } + + #[test] + fn test_extract_azure_resource_group_pattern_match_linux() { + let website_owner_name = "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux".to_string(); + let expected_resource_group = "test-rg".to_string(); + + assert_eq!(extract_resource_group(Some(website_owner_name)), Some(expected_resource_group)); + } + + #[test] + fn test_extract_azure_resource_group_pattern_match_windows() { + let website_owner_name = "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace".to_string(); + let expected_resource_group = "test-rg".to_string(); + + assert_eq!(extract_resource_group(Some(website_owner_name)), Some(expected_resource_group)); + } + + #[test] + fn test_extract_azure_resource_group_no_pattern_match() { + let website_owner_name = "foo".to_string(); + + assert_eq!(extract_resource_group(Some(website_owner_name)), None); + } + + #[test] + #[serial] + fn test_get_azure_resource_group_website_resource_group() { + env::set_var(WEBSITE_RESOURCE_GROUP, "test-rg"); + env::remove_var(DD_AZURE_RESOURCE_GROUP); + assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); + env::remove_var(WEBSITE_RESOURCE_GROUP); + } + + #[test] + #[serial] + fn test_get_azure_resource_group_website_owner_name() { + env::set_var(WEBSITE_OWNER_NAME, "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux"); + env::remove_var(DD_AZURE_RESOURCE_GROUP); + env::remove_var(WEBSITE_RESOURCE_GROUP); + assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); + env::remove_var(WEBSITE_OWNER_NAME); + } + + #[test] + #[serial] + fn test_get_azure_resource_group_flex_consumption_plan() { + env::remove_var(WEBSITE_RESOURCE_GROUP); + env::set_var(DD_AZURE_RESOURCE_GROUP, "test-rg"); + env::set_var(WEBSITE_OWNER_NAME, "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux"); + assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); + env::remove_var(WEBSITE_OWNER_NAME); + env::remove_var(DD_AZURE_RESOURCE_GROUP); + } + + #[test] + #[serial] + fn test_get_azure_resource_group_flex_dd_azure_resource_group_not_set() { + env::remove_var(WEBSITE_RESOURCE_GROUP); + env::remove_var(DD_AZURE_RESOURCE_GROUP); + env::set_var(WEBSITE_OWNER_NAME, "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux"); + assert_eq!(get_azure_resource_group(), None); + env::remove_var(WEBSITE_OWNER_NAME); + env::remove_var(DD_AZURE_RESOURCE_GROUP); + } + } From efe67887b4dbe6e55ccd9a499c3f9ca1f60dbd26 Mon Sep 17 00:00:00 2001 From: Kathie Huang Date: Thu, 25 Sep 2025 11:56:46 -0400 Subject: [PATCH 2/6] Add regex package and run cargo fmt --- crates/datadog-trace-agent/Cargo.toml | 1 + .../datadog-trace-agent/src/env_verifier.rs | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/crates/datadog-trace-agent/Cargo.toml b/crates/datadog-trace-agent/Cargo.toml index dd967d1..0ad479a 100644 --- a/crates/datadog-trace-agent/Cargo.toml +++ b/crates/datadog-trace-agent/Cargo.toml @@ -11,6 +11,7 @@ bench = false anyhow = "1.0" hyper = { version = "1.6", features = ["http1", "client", "server"] } hyper-util = {version = "0.1", features = ["service"] } +regex = "1" tower = { version = "0.5.2", features = ["util"] } http-body-util = "0.1" tokio = { version = "1", features = ["macros", "rt-multi-thread"]} diff --git a/crates/datadog-trace-agent/src/env_verifier.rs b/crates/datadog-trace-agent/src/env_verifier.rs index e811526..0a2e4ba 100644 --- a/crates/datadog-trace-agent/src/env_verifier.rs +++ b/crates/datadog-trace-agent/src/env_verifier.rs @@ -375,7 +375,11 @@ mod tests { use std::{env, fs, path::Path, time::Duration}; use crate::env_verifier::{ - ensure_azure_function_environment, ensure_gcp_function_environment, extract_resource_group, get_region_from_gcp_region_string, AzureVerificationClient, AzureVerificationClientWrapper, GCPInstance, GCPMetadata, GCPProject, GoogleMetadataClient, AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, DD_AZURE_RESOURCE_GROUP, WEBSITE_RESOURCE_GROUP, WEBSITE_OWNER_NAME, get_azure_resource_group + ensure_azure_function_environment, ensure_gcp_function_environment, extract_resource_group, + get_azure_resource_group, get_region_from_gcp_region_string, AzureVerificationClient, + AzureVerificationClientWrapper, GCPInstance, GCPMetadata, GCPProject, GoogleMetadataClient, + AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, DD_AZURE_RESOURCE_GROUP, + WEBSITE_OWNER_NAME, WEBSITE_RESOURCE_GROUP, }; use super::{EnvVerifier, ServerlessEnvVerifier}; @@ -650,18 +654,26 @@ mod tests { #[test] fn test_extract_azure_resource_group_pattern_match_linux() { - let website_owner_name = "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux".to_string(); + let website_owner_name = + "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux".to_string(); let expected_resource_group = "test-rg".to_string(); - assert_eq!(extract_resource_group(Some(website_owner_name)), Some(expected_resource_group)); + assert_eq!( + extract_resource_group(Some(website_owner_name)), + Some(expected_resource_group) + ); } #[test] fn test_extract_azure_resource_group_pattern_match_windows() { - let website_owner_name = "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace".to_string(); + let website_owner_name = + "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace".to_string(); let expected_resource_group = "test-rg".to_string(); - assert_eq!(extract_resource_group(Some(website_owner_name)), Some(expected_resource_group)); + assert_eq!( + extract_resource_group(Some(website_owner_name)), + Some(expected_resource_group) + ); } #[test] @@ -683,7 +695,10 @@ mod tests { #[test] #[serial] fn test_get_azure_resource_group_website_owner_name() { - env::set_var(WEBSITE_OWNER_NAME, "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux"); + env::set_var( + WEBSITE_OWNER_NAME, + "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux", + ); env::remove_var(DD_AZURE_RESOURCE_GROUP); env::remove_var(WEBSITE_RESOURCE_GROUP); assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); @@ -695,7 +710,10 @@ mod tests { fn test_get_azure_resource_group_flex_consumption_plan() { env::remove_var(WEBSITE_RESOURCE_GROUP); env::set_var(DD_AZURE_RESOURCE_GROUP, "test-rg"); - env::set_var(WEBSITE_OWNER_NAME, "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux"); + env::set_var( + WEBSITE_OWNER_NAME, + "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux", + ); assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); env::remove_var(WEBSITE_OWNER_NAME); env::remove_var(DD_AZURE_RESOURCE_GROUP); @@ -706,10 +724,12 @@ mod tests { fn test_get_azure_resource_group_flex_dd_azure_resource_group_not_set() { env::remove_var(WEBSITE_RESOURCE_GROUP); env::remove_var(DD_AZURE_RESOURCE_GROUP); - env::set_var(WEBSITE_OWNER_NAME, "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux"); + env::set_var( + WEBSITE_OWNER_NAME, + "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux", + ); assert_eq!(get_azure_resource_group(), None); env::remove_var(WEBSITE_OWNER_NAME); env::remove_var(DD_AZURE_RESOURCE_GROUP); } - } From cd2aa57b77e283447752d8da4f00f9b4632f2889 Mon Sep 17 00:00:00 2001 From: Kathie Huang Date: Thu, 25 Sep 2025 17:57:40 -0400 Subject: [PATCH 3/6] Just check WEBSITE_SKU env var instead of repeating libdatadog regex logic --- .../datadog-trace-agent/src/env_verifier.rs | 130 ++++-------------- 1 file changed, 29 insertions(+), 101 deletions(-) diff --git a/crates/datadog-trace-agent/src/env_verifier.rs b/crates/datadog-trace-agent/src/env_verifier.rs index 0a2e4ba..f1f2a1a 100644 --- a/crates/datadog-trace-agent/src/env_verifier.rs +++ b/crates/datadog-trace-agent/src/env_verifier.rs @@ -5,7 +5,6 @@ use async_trait::async_trait; use ddcommon::hyper_migration; use http_body_util::BodyExt; use hyper::{Method, Request}; -use regex::Regex; use serde::{Deserialize, Serialize}; use std::env; use std::fs; @@ -23,10 +22,9 @@ const AZURE_WINDOWS_FUNCTION_ROOT_PATH_STR: &str = "C:\\home\\site\\wwwroot"; const AZURE_HOST_JSON_NAME: &str = "host.json"; const AZURE_FUNCTION_JSON_NAME: &str = "function.json"; -// Azure environment variables for resource group detection +// Azure environment variables for Flex consumption plan detection const DD_AZURE_RESOURCE_GROUP: &str = "DD_AZURE_RESOURCE_GROUP"; -const WEBSITE_RESOURCE_GROUP: &str = "WEBSITE_RESOURCE_GROUP"; -const WEBSITE_OWNER_NAME: &str = "WEBSITE_OWNER_NAME"; +const WEBSITE_SKU: &str = "WEBSITE_SKU"; #[derive(Default, Debug, Deserialize, Serialize, Eq, PartialEq)] pub struct GCPMetadata { @@ -248,26 +246,11 @@ async fn get_gcp_metadata_from_body(body: hyper_migration::Body) -> anyhow::Resu Ok(gcp_metadata) } -/// Determines the Azure resource group using the same logic as libdatadog -/// Returns None if running in Flex consumption plan without DD_AZURE_RESOURCE_GROUP set -fn get_azure_resource_group() -> Option { - env::var(DD_AZURE_RESOURCE_GROUP) - .ok() - .or_else(|| env::var(WEBSITE_RESOURCE_GROUP).ok()) - .or_else(|| extract_resource_group(env::var(WEBSITE_OWNER_NAME).ok())) - .filter(|rg| rg != "flex") -} - -/// Extracts resource group from WEBSITE_OWNER_NAME -/// This uses the exact same regex logic as libdatadog's AzureMetadata::extract_resource_group -fn extract_resource_group(s: Option) -> Option { - #[allow(clippy::unwrap_used)] - let re: Regex = Regex::new(r".+\+(.+)-.+webspace(-Linux)?").unwrap(); - - s.as_ref().and_then(|text| { - re.captures(text) - .and_then(|caps| caps.get(1).map(|m| m.as_str().to_string())) - }) +/// Checks if we're running in Azure Flex Consumption plan without DD_AZURE_RESOURCE_GROUP set +/// This would cause billing issues, so we should shut down the trace agent +fn is_azure_flex_without_resource_group() -> bool { + env::var(WEBSITE_SKU).map(|sku| sku == "FlexConsumption").unwrap_or(false) + && env::var(DD_AZURE_RESOURCE_GROUP).is_err() } async fn verify_azure_environment_or_exit(os: &str) { @@ -281,10 +264,12 @@ async fn verify_azure_environment_or_exit(os: &str) { process::exit(1); } } - if let None = get_azure_resource_group() { + + // Check for Azure Flex Consumption plan without DD_AZURE_RESOURCE_GROUP + if is_azure_flex_without_resource_group() { error!( - "Unable to determine Azure resource group. If you are using Azure Functions on the Flex Consumption plan, \ - please add your resource group name as an environment variable called `DD_AZURE_RESOURCE_GROUP` in Azure App settings." + "Azure Flex Consumption plan detected without DD_AZURE_RESOURCE_GROUP set. \ + Please add your resource group name as an environment variable called `DD_AZURE_RESOURCE_GROUP` in Azure App settings." ); process::exit(1); } @@ -375,11 +360,9 @@ mod tests { use std::{env, fs, path::Path, time::Duration}; use crate::env_verifier::{ - ensure_azure_function_environment, ensure_gcp_function_environment, extract_resource_group, - get_azure_resource_group, get_region_from_gcp_region_string, AzureVerificationClient, + ensure_azure_function_environment, ensure_gcp_function_environment, get_region_from_gcp_region_string, is_azure_flex_without_resource_group, AzureVerificationClient, AzureVerificationClientWrapper, GCPInstance, GCPMetadata, GCPProject, GoogleMetadataClient, - AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, DD_AZURE_RESOURCE_GROUP, - WEBSITE_OWNER_NAME, WEBSITE_RESOURCE_GROUP, + AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, WEBSITE_SKU, DD_AZURE_RESOURCE_GROUP, }; use super::{EnvVerifier, ServerlessEnvVerifier}; @@ -652,84 +635,29 @@ mod tests { assert_eq!(files, vec![AZURE_HOST_JSON_NAME]); } - #[test] - fn test_extract_azure_resource_group_pattern_match_linux() { - let website_owner_name = - "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux".to_string(); - let expected_resource_group = "test-rg".to_string(); - - assert_eq!( - extract_resource_group(Some(website_owner_name)), - Some(expected_resource_group) - ); - } - - #[test] - fn test_extract_azure_resource_group_pattern_match_windows() { - let website_owner_name = - "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace".to_string(); - let expected_resource_group = "test-rg".to_string(); - - assert_eq!( - extract_resource_group(Some(website_owner_name)), - Some(expected_resource_group) - ); - } - - #[test] - fn test_extract_azure_resource_group_no_pattern_match() { - let website_owner_name = "foo".to_string(); - - assert_eq!(extract_resource_group(Some(website_owner_name)), None); - } - - #[test] - #[serial] - fn test_get_azure_resource_group_website_resource_group() { - env::set_var(WEBSITE_RESOURCE_GROUP, "test-rg"); - env::remove_var(DD_AZURE_RESOURCE_GROUP); - assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); - env::remove_var(WEBSITE_RESOURCE_GROUP); - } - #[test] #[serial] - fn test_get_azure_resource_group_website_owner_name() { - env::set_var( - WEBSITE_OWNER_NAME, - "00000000-0000-0000-0000-000000000000+test-rg-EastUSwebspace-Linux", - ); + fn test_is_azure_flex_without_resource_group_true() { env::remove_var(DD_AZURE_RESOURCE_GROUP); - env::remove_var(WEBSITE_RESOURCE_GROUP); - assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); - env::remove_var(WEBSITE_OWNER_NAME); + env::set_var(WEBSITE_SKU, "FlexConsumption"); + assert!(is_azure_flex_without_resource_group()); + env::remove_var(WEBSITE_SKU); } - + #[test] - #[serial] - fn test_get_azure_resource_group_flex_consumption_plan() { - env::remove_var(WEBSITE_RESOURCE_GROUP); - env::set_var(DD_AZURE_RESOURCE_GROUP, "test-rg"); - env::set_var( - WEBSITE_OWNER_NAME, - "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux", - ); - assert_eq!(get_azure_resource_group(), Some("test-rg".to_string())); - env::remove_var(WEBSITE_OWNER_NAME); + fn test_is_azure_flex_without_resource_group_false_resource_group_set() { + env::set_var(DD_AZURE_RESOURCE_GROUP, "test-resource-group"); + env::set_var(WEBSITE_SKU, "FlexConsumption"); + assert!(!is_azure_flex_without_resource_group()); + env::remove_var(WEBSITE_SKU); env::remove_var(DD_AZURE_RESOURCE_GROUP); } #[test] - #[serial] - fn test_get_azure_resource_group_flex_dd_azure_resource_group_not_set() { - env::remove_var(WEBSITE_RESOURCE_GROUP); - env::remove_var(DD_AZURE_RESOURCE_GROUP); - env::set_var( - WEBSITE_OWNER_NAME, - "00000000-0000-0000-0000-000000000000+flex-EastUSwebspace-Linux", - ); - assert_eq!(get_azure_resource_group(), None); - env::remove_var(WEBSITE_OWNER_NAME); + fn test_is_azure_flex_without_resource_group_false_not_flex() { env::remove_var(DD_AZURE_RESOURCE_GROUP); + env::set_var(WEBSITE_SKU, "ElasticPremium"); + assert!(!is_azure_flex_without_resource_group()); + env::remove_var(WEBSITE_SKU); } -} +} \ No newline at end of file From deb2062e9259efc405824d969ca74273a4ee81c2 Mon Sep 17 00:00:00 2001 From: Kathie Huang Date: Thu, 25 Sep 2025 17:59:10 -0400 Subject: [PATCH 4/6] nit: ran cargo fmt --- crates/datadog-trace-agent/src/env_verifier.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/datadog-trace-agent/src/env_verifier.rs b/crates/datadog-trace-agent/src/env_verifier.rs index f1f2a1a..cdeb908 100644 --- a/crates/datadog-trace-agent/src/env_verifier.rs +++ b/crates/datadog-trace-agent/src/env_verifier.rs @@ -249,7 +249,9 @@ async fn get_gcp_metadata_from_body(body: hyper_migration::Body) -> anyhow::Resu /// Checks if we're running in Azure Flex Consumption plan without DD_AZURE_RESOURCE_GROUP set /// This would cause billing issues, so we should shut down the trace agent fn is_azure_flex_without_resource_group() -> bool { - env::var(WEBSITE_SKU).map(|sku| sku == "FlexConsumption").unwrap_or(false) + env::var(WEBSITE_SKU) + .map(|sku| sku == "FlexConsumption") + .unwrap_or(false) && env::var(DD_AZURE_RESOURCE_GROUP).is_err() } @@ -264,7 +266,7 @@ async fn verify_azure_environment_or_exit(os: &str) { process::exit(1); } } - + // Check for Azure Flex Consumption plan without DD_AZURE_RESOURCE_GROUP if is_azure_flex_without_resource_group() { error!( @@ -360,9 +362,11 @@ mod tests { use std::{env, fs, path::Path, time::Duration}; use crate::env_verifier::{ - ensure_azure_function_environment, ensure_gcp_function_environment, get_region_from_gcp_region_string, is_azure_flex_without_resource_group, AzureVerificationClient, - AzureVerificationClientWrapper, GCPInstance, GCPMetadata, GCPProject, GoogleMetadataClient, - AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, WEBSITE_SKU, DD_AZURE_RESOURCE_GROUP, + ensure_azure_function_environment, ensure_gcp_function_environment, + get_region_from_gcp_region_string, is_azure_flex_without_resource_group, + AzureVerificationClient, AzureVerificationClientWrapper, GCPInstance, GCPMetadata, + GCPProject, GoogleMetadataClient, AZURE_FUNCTION_JSON_NAME, AZURE_HOST_JSON_NAME, + DD_AZURE_RESOURCE_GROUP, WEBSITE_SKU, }; use super::{EnvVerifier, ServerlessEnvVerifier}; @@ -643,7 +647,7 @@ mod tests { assert!(is_azure_flex_without_resource_group()); env::remove_var(WEBSITE_SKU); } - + #[test] fn test_is_azure_flex_without_resource_group_false_resource_group_set() { env::set_var(DD_AZURE_RESOURCE_GROUP, "test-resource-group"); @@ -660,4 +664,4 @@ mod tests { assert!(!is_azure_flex_without_resource_group()); env::remove_var(WEBSITE_SKU); } -} \ No newline at end of file +} From caa7e5ca2f06472343de1cde8dd00bc2e98d8b81 Mon Sep 17 00:00:00 2001 From: Kathie Huang Date: Fri, 26 Sep 2025 16:39:05 -0400 Subject: [PATCH 5/6] Remove unused regex crate from datadog-trace-agent --- crates/datadog-trace-agent/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/datadog-trace-agent/Cargo.toml b/crates/datadog-trace-agent/Cargo.toml index 0ad479a..dd967d1 100644 --- a/crates/datadog-trace-agent/Cargo.toml +++ b/crates/datadog-trace-agent/Cargo.toml @@ -11,7 +11,6 @@ bench = false anyhow = "1.0" hyper = { version = "1.6", features = ["http1", "client", "server"] } hyper-util = {version = "0.1", features = ["service"] } -regex = "1" tower = { version = "0.5.2", features = ["util"] } http-body-util = "0.1" tokio = { version = "1", features = ["macros", "rt-multi-thread"]} From e89748c464a2dc93076622d6dcccddedfeebaa7f Mon Sep 17 00:00:00 2001 From: Kathie Huang Date: Mon, 29 Sep 2025 13:36:20 -0400 Subject: [PATCH 6/6] Fix tests --- crates/datadog-trace-agent/src/env_verifier.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/datadog-trace-agent/src/env_verifier.rs b/crates/datadog-trace-agent/src/env_verifier.rs index cdeb908..a22d929 100644 --- a/crates/datadog-trace-agent/src/env_verifier.rs +++ b/crates/datadog-trace-agent/src/env_verifier.rs @@ -642,26 +642,22 @@ mod tests { #[test] #[serial] fn test_is_azure_flex_without_resource_group_true() { - env::remove_var(DD_AZURE_RESOURCE_GROUP); env::set_var(WEBSITE_SKU, "FlexConsumption"); assert!(is_azure_flex_without_resource_group()); - env::remove_var(WEBSITE_SKU); } #[test] + #[serial] fn test_is_azure_flex_without_resource_group_false_resource_group_set() { env::set_var(DD_AZURE_RESOURCE_GROUP, "test-resource-group"); env::set_var(WEBSITE_SKU, "FlexConsumption"); assert!(!is_azure_flex_without_resource_group()); - env::remove_var(WEBSITE_SKU); - env::remove_var(DD_AZURE_RESOURCE_GROUP); } #[test] + #[serial] fn test_is_azure_flex_without_resource_group_false_not_flex() { - env::remove_var(DD_AZURE_RESOURCE_GROUP); env::set_var(WEBSITE_SKU, "ElasticPremium"); assert!(!is_azure_flex_without_resource_group()); - env::remove_var(WEBSITE_SKU); } }