From deb6e3bed31c24ca30ee19238dbb4bd955089759 Mon Sep 17 00:00:00 2001 From: Nina Rei Date: Mon, 9 Nov 2026 11:47:32 -0500 Subject: [PATCH 1/4] fix: use a combined Compat runtime metadata hint --- README.md | 16 +++++++++++- crates/metadata/src/platform/azure.rs | 28 ++++++++++++++++++++- crates/metadata/src/platform/gcp.rs | 23 ++++++++++++++++-- crates/metadata/src/platform/mod.rs | 35 +++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 96b02ab7..5f600e46 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,24 @@ A collection of libraries and binaries used for instrumenting AWS Lambda Functions, Azure Functions, and Azure Spring Apps. +## Compat inventory runtime metadata + +With `DD_SERVERLESS_COMPAT_METADATA_ENABLED=true`, Compat wrappers pass the language +engine to the child binary using `DD_SERVERLESS_COMPAT_RUNTIME` (for example, +`python3.13.7`, not the wrapper package version). +This best-effort hint takes precedence over platform hints for the inventory `runtime` +field. Missing, empty, or `unknown` hints retain the existing platform-based detection for +older wrappers. Platform-owned environment variables are not overwritten. + +This does not change `DD_SERVERLESS_COMPAT_VERSION`, which identifies the wrapper +package. Release a binary with this reader before bundling the updated wrappers; +older binaries do not read the new hint. Customers do not need to set it. Setting +`DD_SERVERLESS_COMPAT_METADATA_ENABLED=false` disables inventory reporting. + ## Development Install the git pre-push hook (runs `cargo fmt --check` and `cargo clippy -D warnings` before each push): ```sh git config core.hooksPath .githooks -``` \ No newline at end of file +``` diff --git a/crates/metadata/src/platform/azure.rs b/crates/metadata/src/platform/azure.rs index 365dca9a..c977b3f1 100644 --- a/crates/metadata/src/platform/azure.rs +++ b/crates/metadata/src/platform/azure.rs @@ -29,6 +29,7 @@ pub(super) fn collect() -> Option { } fn collect_from(env: E) -> Option { + let runtime = super::wrapper_runtime(&env); let azure = AzureMetadata::new_function(env)?; let resource_name = known_value(azure.get_site_name())?.to_string(); let resource_id = known_value(azure.get_resource_id())?.to_string(); @@ -44,7 +45,9 @@ fn collect_from(env: E) -> Option { metadata.insert(field.into(), Value::String(value.to_string())); } } - if let Some(runtime) = runtime_with_version(azure.get_runtime(), azure.get_runtime_version()) { + if let Some(runtime) = + runtime.or_else(|| runtime_with_version(azure.get_runtime(), azure.get_runtime_version())) + { metadata.insert("runtime".into(), Value::String(runtime)); } @@ -179,4 +182,27 @@ mod tests { .expect("Azure metadata should be available"); assert_eq!(data.metadata["runtime"], "dotnet"); } + + #[test] + fn wrapper_runtime_falls_back_to_platform_detection() { + for (runtime, expected) in [ + (Some("python3.13.7"), "python3.13.7"), + (None, "python3.12"), + (Some(""), "python3.12"), + (Some("unknown"), "python3.12"), + ] { + let mut values = vec![ + ("FUNCTIONS_WORKER_RUNTIME", "python"), + ("FUNCTIONS_WORKER_RUNTIME_VERSION", "3.12"), + ("WEBSITE_OWNER_NAME", "abc123+my-rg-eastuswebspace"), + ("WEBSITE_RESOURCE_GROUP", "my-rg"), + ("WEBSITE_SITE_NAME", "my-func-app"), + ]; + if let Some(runtime) = runtime { + values.push(("DD_SERVERLESS_COMPAT_RUNTIME", runtime)); + } + let data = collect_from(FakeEnv::new(&values)).unwrap(); + assert_eq!(data.metadata["runtime"], expected); + } + } } diff --git a/crates/metadata/src/platform/gcp.rs b/crates/metadata/src/platform/gcp.rs index ae9cd0a8..391b0368 100644 --- a/crates/metadata/src/platform/gcp.rs +++ b/crates/metadata/src/platform/gcp.rs @@ -102,6 +102,9 @@ fn first_env(env: &impl QueryEnv, names: &[&str]) -> Option { } fn detect_runtime(env: &impl QueryEnv) -> Option { + if let Some(runtime) = super::wrapper_runtime(env) { + return Some(runtime); + } for (runtime, variable) in [ ("node", "NODE_VERSION"), ("python", "PYTHON_VERSION"), @@ -308,8 +311,24 @@ mod tests { #[test] fn detects_runtime_from_platform_environment() { - let env = FakeEnv::new(&[("PYTHON_VERSION", "3.12.7")]); - assert_eq!(detect_runtime(&env), Some("python3.12.7".into())); + for (overrides, expected) in [ + (vec![], "python3.12.7"), + ( + vec![ + ("DD_SERVERLESS_COMPAT_RUNTIME", "python3.13.7"), + ("NODE_VERSION", "22.0.0"), + ], + "python3.13.7", + ), + (vec![("DD_SERVERLESS_COMPAT_RUNTIME", "")], "python3.12.7"), + (vec![("DD_SERVERLESS_COMPAT_RUNTIME", "unknown")], "python3.12.7"), + ] { + let mut values = vec![("PYTHON_VERSION", "3.12.7")]; + values.extend(overrides); + let env = FakeEnv::new(&values); + assert_eq!(detect_runtime(&env).as_deref(), Some(expected)); + } + assert_eq!(detect_runtime(&FakeEnv::new(&[])), None); } #[tokio::test] diff --git a/crates/metadata/src/platform/mod.rs b/crates/metadata/src/platform/mod.rs index e23c2c46..e28050f3 100644 --- a/crates/metadata/src/platform/mod.rs +++ b/crates/metadata/src/platform/mod.rs @@ -4,6 +4,7 @@ mod azure; mod gcp; +use libdd_common::azure_app_services::QueryEnv; use libdd_trace_utils::trace_utils::EnvironmentType; use serde_json::{Map, Value}; @@ -14,6 +15,13 @@ pub(crate) struct PlatformData { pub metadata: Map, } +// Wrapper-supplied engine identity takes precedence over platform hints. +fn wrapper_runtime(env: &impl QueryEnv) -> Option { + env.get_var("DD_SERVERLESS_COMPAT_RUNTIME") + .map(|value| value.trim().to_owned()) + .filter(|value| !value.is_empty() && !value.eq_ignore_ascii_case("unknown")) +} + pub(crate) async fn collect(env_type: &EnvironmentType) -> Option { match env_type { EnvironmentType::AzureFunction => azure::collect(), @@ -21,3 +29,30 @@ pub(crate) async fn collect(env_type: &EnvironmentType) -> Option EnvironmentType::LambdaFunction | EnvironmentType::AzureSpringApp => None, } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_env::FakeEnv; + + #[test] + fn wrapper_runtime_is_an_optional_best_effort_hint() { + for (value, expected) in [ + ("node22.1.0", Some("node22.1.0")), + ("python3.13.7", Some("python3.13.7")), + ("java21.0.1+12", Some("java21.0.1+12")), + ("go1.24.0", Some("go1.24.0")), + ("dotnet8.0.12", Some("dotnet8.0.12")), + ("dotnet-isolated8.0.12", Some("dotnet-isolated8.0.12")), + (" python3.13.7 ", Some("python3.13.7")), + ("", None), + (" ", None), + ("unknown", None), + (" UNKNOWN ", None), + ] { + let env = FakeEnv::new(&[("DD_SERVERLESS_COMPAT_RUNTIME", value)]); + assert_eq!(wrapper_runtime(&env).as_deref(), expected); + } + assert_eq!(wrapper_runtime(&FakeEnv::new(&[])), None); + } +} From ed4bb98d9001988d16f374ce77541b14d6bc8393 Mon Sep 17 00:00:00 2001 From: Nina Rei Date: Mon, 9 Nov 2026 13:03:11 -0500 Subject: [PATCH 2/4] style: format runtime fallback test case --- crates/metadata/src/platform/gcp.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/metadata/src/platform/gcp.rs b/crates/metadata/src/platform/gcp.rs index 391b0368..c193c739 100644 --- a/crates/metadata/src/platform/gcp.rs +++ b/crates/metadata/src/platform/gcp.rs @@ -321,7 +321,10 @@ mod tests { "python3.13.7", ), (vec![("DD_SERVERLESS_COMPAT_RUNTIME", "")], "python3.12.7"), - (vec![("DD_SERVERLESS_COMPAT_RUNTIME", "unknown")], "python3.12.7"), + ( + vec![("DD_SERVERLESS_COMPAT_RUNTIME", "unknown")], + "python3.12.7", + ), ] { let mut values = vec![("PYTHON_VERSION", "3.12.7")]; values.extend(overrides); From a5c61b86bec6df2748101267cdb020657fd6a393 Mon Sep 17 00:00:00 2001 From: Nina Rei Date: Mon, 9 Nov 2026 13:18:35 -0500 Subject: [PATCH 3/4] test: trim redundant runtime hint cases --- crates/metadata/src/platform/mod.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/metadata/src/platform/mod.rs b/crates/metadata/src/platform/mod.rs index e28050f3..3bfd5729 100644 --- a/crates/metadata/src/platform/mod.rs +++ b/crates/metadata/src/platform/mod.rs @@ -38,12 +38,8 @@ mod tests { #[test] fn wrapper_runtime_is_an_optional_best_effort_hint() { for (value, expected) in [ - ("node22.1.0", Some("node22.1.0")), ("python3.13.7", Some("python3.13.7")), ("java21.0.1+12", Some("java21.0.1+12")), - ("go1.24.0", Some("go1.24.0")), - ("dotnet8.0.12", Some("dotnet8.0.12")), - ("dotnet-isolated8.0.12", Some("dotnet-isolated8.0.12")), (" python3.13.7 ", Some("python3.13.7")), ("", None), (" ", None), From e7d9cebc04229a71e9370821ad91e797dd3249e7 Mon Sep 17 00:00:00 2001 From: Nina Rei Date: Wed, 11 Nov 2026 12:50:24 -0500 Subject: [PATCH 4/4] docs: preserve existing README end-of-file formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f600e46..1fbefefc 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,4 @@ Install the git pre-push hook (runs `cargo fmt --check` and `cargo clippy -D war ```sh git config core.hooksPath .githooks -``` +``` \ No newline at end of file