Skip to content

Commit 75b6c94

Browse files
committed
add DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED
1 parent ba9449f commit 75b6c94

2 files changed

Lines changed: 69 additions & 11 deletions

File tree

crates/datadog-trace-agent/src/config.rs

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ pub struct Config {
115115
pub proxy_url: Option<String>,
116116
pub env: String,
117117
pub peer_tags: Vec<String>,
118+
/// Gates additional_metric_tags and related config.
119+
pub experimental_features_enabled: bool,
118120
/// Tag keys extracted from spans and used as additional aggregation dimensions in stats.
121+
/// Only populated when experimental_features_enabled is true.
119122
pub additional_metric_tags: Vec<String>,
120123
/// Configures the per-bucket cardinality limit for additional_metric_tags stat entries.
124+
/// Only populated when experimental_features_enabled is true.
121125
pub additional_metric_tags_cardinality_limit: Option<usize>,
122126
/// Whether the agent should compute trace stats
123127
pub agent_stats_computation_enabled: bool,
@@ -220,6 +224,10 @@ impl Config {
220224
Tags::new()
221225
};
222226

227+
let experimental_features_enabled = env::var("DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED")
228+
.map(|val| val.to_lowercase() == "true")
229+
.unwrap_or(false);
230+
223231
#[allow(clippy::unwrap_used)]
224232
Ok(Config {
225233
app_name: Some(app_name),
@@ -266,17 +274,24 @@ impl Config {
266274
tags,
267275
env: env::var("DD_ENV").unwrap_or_else(|_| "none".to_string()),
268276
peer_tags: peer_tag_keys()?,
269-
additional_metric_tags: env::var("DD_TRACE_STATS_ADDITIONAL_TAGS")
270-
.ok()
271-
.filter(|s| !s.is_empty())
272-
.map(|s| s.split(',').map(str::to_owned).collect())
273-
.unwrap_or_default(),
274-
additional_metric_tags_cardinality_limit: env::var(
275-
"DD_TRACE_STATS_ADDITIONAL_TAGS_CARDINALITY_LIMIT",
276-
)
277-
.ok()
278-
.and_then(|s| s.parse::<usize>().ok())
279-
.filter(|&n| n > 0),
277+
experimental_features_enabled,
278+
additional_metric_tags: if experimental_features_enabled {
279+
env::var("DD_TRACE_STATS_ADDITIONAL_TAGS")
280+
.ok()
281+
.filter(|s| !s.is_empty())
282+
.map(|s| s.split(',').map(str::to_owned).collect())
283+
.unwrap_or_default()
284+
} else {
285+
vec![]
286+
},
287+
additional_metric_tags_cardinality_limit: if experimental_features_enabled {
288+
env::var("DD_TRACE_STATS_ADDITIONAL_TAGS_CARDINALITY_LIMIT")
289+
.ok()
290+
.and_then(|s| s.parse::<usize>().ok())
291+
.filter(|&n| n > 0)
292+
} else {
293+
None
294+
},
280295
agent_stats_computation_enabled: env::var("DD_AGENT_STATS_COMPUTATION_ENABLED")
281296
.map(|val| val.to_lowercase() == "true")
282297
.unwrap_or(false),
@@ -760,6 +775,46 @@ mod tests {
760775
},
761776
);
762777
}
778+
779+
#[test]
780+
#[serial]
781+
fn test_additional_metric_tags_gated_by_experimental_flag() {
782+
let base_vars = [
783+
("DD_API_KEY", Some("_not_a_real_key_")),
784+
("K_SERVICE", Some("function_name")),
785+
("FUNCTION_TARGET", Some("function_target")),
786+
("DD_TRACE_STATS_ADDITIONAL_TAGS", Some("region,tenant_id")),
787+
];
788+
789+
temp_env::with_vars(
790+
base_vars
791+
.iter()
792+
.cloned()
793+
.chain([("DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED", Some("false"))])
794+
.collect::<Vec<_>>(),
795+
|| {
796+
let config = config::Config::new().unwrap();
797+
assert!(!config.experimental_features_enabled);
798+
assert!(config.additional_metric_tags.is_empty());
799+
},
800+
);
801+
802+
temp_env::with_vars(
803+
base_vars
804+
.iter()
805+
.cloned()
806+
.chain([("DD_TRACE_EXPERIMENTAL_FEATURES_ENABLED", Some("true"))])
807+
.collect::<Vec<_>>(),
808+
|| {
809+
let config = config::Config::new().unwrap();
810+
assert!(config.experimental_features_enabled);
811+
assert_eq!(
812+
config.additional_metric_tags,
813+
vec!["region".to_string(), "tenant_id".to_string()]
814+
);
815+
},
816+
);
817+
}
763818
}
764819

765820
/// Test helpers for creating Config instances in tests
@@ -797,6 +852,7 @@ pub mod test_helpers {
797852
proxy_url: None,
798853
env: "none".to_string(),
799854
peer_tags: peer_tag_keys().unwrap(),
855+
experimental_features_enabled: false,
800856
additional_metric_tags: vec![],
801857
additional_metric_tags_cardinality_limit: None,
802858
agent_stats_computation_enabled: false,

crates/datadog-trace-agent/src/trace_processor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ mod tests {
285285
tags: Tags::from_env_string("env:test,service:my-service"),
286286
env: "test-env".to_string(),
287287
peer_tags: peer_tag_keys().unwrap(),
288+
experimental_features_enabled: false,
288289
additional_metric_tags: vec![],
290+
additional_metric_tags_cardinality_limit: None,
289291
agent_stats_computation_enabled: false,
290292
}
291293
}

0 commit comments

Comments
 (0)