Skip to content

Commit ee2e433

Browse files
committed
feat: add DD_APM_SPAN_DERIVED_PRIMARY_TAGS config
Parse the env var and wire it through Config for use as additional APM stats aggregation dimensions. The actual SpanConcentrator call is gated on DataDog/libdatadog#1858. 🤖 Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent edeb5ab commit ee2e433

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

bottlecap/src/config/env.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ pub struct EnvConfig {
217217
/// @env `DD_APM_FEATURES`
218218
#[serde(deserialize_with = "deserialize_array_from_comma_separated_string")]
219219
pub apm_features: Vec<String>,
220+
/// @env `DD_APM_SPAN_DERIVED_PRIMARY_TAGS`
221+
///
222+
/// Comma-separated list of tag keys to extract from spans for use as
223+
/// additional aggregation dimensions in APM stats.
224+
#[serde(deserialize_with = "deserialize_array_from_comma_separated_string")]
225+
pub apm_span_derived_primary_tags: Vec<String>,
220226
/// @env `DD_APM_ADDITIONAL_ENDPOINTS`
221227
///
222228
/// Additional endpoints to send traces to.
@@ -559,6 +565,7 @@ fn merge_config(config: &mut Config, env_config: &EnvConfig) {
559565
);
560566
merge_option_to_value!(config, env_config, apm_config_compression_level);
561567
merge_vec!(config, env_config, apm_features);
568+
merge_vec!(config, env_config, apm_span_derived_primary_tags);
562569
merge_hashmap!(config, env_config, apm_additional_endpoints);
563570
merge_option!(config, env_config, apm_filter_tags_require);
564571
merge_option!(config, env_config, apm_filter_tags_reject);
@@ -796,6 +803,10 @@ mod tests {
796803
"DD_APM_FEATURES",
797804
"enable_otlp_compute_top_level_by_span_kind,enable_stats_by_span_kind",
798805
);
806+
jail.set_env(
807+
"DD_APM_SPAN_DERIVED_PRIMARY_TAGS",
808+
"aws.s3.bucket,customer_tier",
809+
);
799810
jail.set_env("DD_APM_ADDITIONAL_ENDPOINTS", "{\"https://trace.agent.datadoghq.com\": [\"apikey2\", \"apikey3\"], \"https://trace.agent.datadoghq.eu\": [\"apikey4\"]}");
800811
jail.set_env("DD_APM_FILTER_TAGS_REQUIRE", "env:production service:api");
801812
jail.set_env("DD_APM_FILTER_TAGS_REJECT", "debug:true env:test");
@@ -966,6 +977,10 @@ mod tests {
966977
"enable_otlp_compute_top_level_by_span_kind".to_string(),
967978
"enable_stats_by_span_kind".to_string(),
968979
],
980+
apm_span_derived_primary_tags: vec![
981+
"aws.s3.bucket".to_string(),
982+
"customer_tier".to_string(),
983+
],
969984
apm_additional_endpoints: HashMap::from([
970985
(
971986
"https://trace.agent.datadoghq.com".to_string(),

bottlecap/src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ pub struct Config {
288288
pub apm_config_obfuscation_http_remove_paths_with_digits: bool,
289289
pub apm_config_compression_level: i32,
290290
pub apm_features: Vec<String>,
291+
pub apm_span_derived_primary_tags: Vec<String>,
291292
pub apm_additional_endpoints: HashMap<String, Vec<String>>,
292293
pub apm_filter_tags_require: Option<Vec<String>>,
293294
pub apm_filter_tags_reject: Option<Vec<String>>,
@@ -418,6 +419,7 @@ impl Default for Config {
418419
apm_config_obfuscation_http_remove_paths_with_digits: false,
419420
apm_config_compression_level: 3,
420421
apm_features: vec![],
422+
apm_span_derived_primary_tags: vec![],
421423
apm_additional_endpoints: HashMap::new(),
422424
apm_filter_tags_require: None,
423425
apm_filter_tags_reject: None,

bottlecap/src/config/yaml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ api_security_sample_delay: 60 # Seconds
960960
"enable_otlp_compute_top_level_by_span_kind".to_string(),
961961
"enable_stats_by_span_kind".to_string(),
962962
],
963+
apm_span_derived_primary_tags: vec![],
963964
apm_additional_endpoints: HashMap::from([
964965
(
965966
"https://trace.agent.datadoghq.com".to_string(),

bottlecap/src/traces/stats_concentrator_service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ impl StatsConcentratorService {
114114
let (tx, rx) = mpsc::unbounded_channel();
115115
let handle = StatsConcentratorHandle::new(tx);
116116
// TODO: set span_kinds_stats_computed and peer_tag_keys
117+
// TODO: call concentrator.set_span_derived_primary_tag_keys(config.apm_span_derived_primary_tags.clone())
118+
// after bumping libdatadog to include DataDog/libdatadog#1858
117119
let concentrator = SpanConcentrator::new(
118120
Duration::from_nanos(BUCKET_DURATION_NS),
119121
SystemTime::now(),

0 commit comments

Comments
 (0)