@@ -10,8 +10,9 @@ use crate::{
10
10
Config , ConfigError , ConfigSource ,
11
11
additional_endpoints:: deserialize_additional_endpoints,
12
12
apm_replace_rule:: deserialize_apm_replace_rules,
13
- deserialize_array_from_comma_separated_string, deserialize_key_value_pairs,
14
- deserialize_optional_bool_from_anything, deserialize_optional_duration_from_microseconds,
13
+ deserialize_apm_filter_tags, deserialize_array_from_comma_separated_string,
14
+ deserialize_key_value_pairs, deserialize_optional_bool_from_anything,
15
+ deserialize_optional_duration_from_microseconds,
15
16
deserialize_optional_duration_from_seconds, deserialize_string_or_int,
16
17
flush_strategy:: FlushStrategy ,
17
18
log_level:: LogLevel ,
@@ -180,6 +181,34 @@ pub struct EnvConfig {
180
181
/// <https://docs.datadoghq.com/agent/configuration/dual-shipping/?tab=helm#environment-variable-configuration-1>
181
182
#[ serde( deserialize_with = "deserialize_additional_endpoints" ) ]
182
183
pub apm_additional_endpoints : HashMap < String , Vec < String > > ,
184
+ /// @env `DD_APM_FILTER_TAGS_REQUIRE`
185
+ ///
186
+ /// Space-separated list of key:value tag pairs that spans must match to be kept.
187
+ /// Only spans matching at least one of these tags will be sent to Datadog.
188
+ /// Example: "env:production service:api-gateway"
189
+ #[ serde( deserialize_with = "deserialize_apm_filter_tags" ) ]
190
+ pub apm_filter_tags_require : Option < Vec < String > > ,
191
+ /// @env `DD_APM_FILTER_TAGS_REJECT`
192
+ ///
193
+ /// Space-separated list of key:value tag pairs that will cause spans to be filtered out.
194
+ /// Spans matching any of these tags will be dropped.
195
+ /// Example: "env:development debug:true name:health.check"
196
+ #[ serde( deserialize_with = "deserialize_apm_filter_tags" ) ]
197
+ pub apm_filter_tags_reject : Option < Vec < String > > ,
198
+ /// @env `DD_APM_FILTER_TAGS_REGEX_REQUIRE`
199
+ ///
200
+ /// Space-separated list of key:value tag pairs with regex values that spans must match to be kept.
201
+ /// Only spans matching at least one of these regex patterns will be sent to Datadog.
202
+ /// Example: "env:^prod.*$ service:^api-.*$"
203
+ #[ serde( deserialize_with = "deserialize_apm_filter_tags" ) ]
204
+ pub apm_filter_tags_regex_require : Option < Vec < String > > ,
205
+ /// @env `DD_APM_FILTER_TAGS_REGEX_REJECT`
206
+ ///
207
+ /// Space-separated list of key:value tag pairs with regex values that will cause spans to be filtered out.
208
+ /// Spans matching any of these regex patterns will be dropped.
209
+ /// Example: "env:^test.*$ debug:^true$"
210
+ #[ serde( deserialize_with = "deserialize_apm_filter_tags" ) ]
211
+ pub apm_filter_tags_regex_reject : Option < Vec < String > > ,
183
212
/// @env `DD_TRACE_AWS_SERVICE_REPRESENTATION_ENABLED`
184
213
///
185
214
/// Enable the new AWS-resource naming logic in the tracer.
@@ -388,6 +417,10 @@ fn merge_config(config: &mut Config, env_config: &EnvConfig) {
388
417
merge_option_to_value ! ( config, env_config, apm_config_compression_level) ;
389
418
merge_vec ! ( config, env_config, apm_features) ;
390
419
merge_hashmap ! ( config, env_config, apm_additional_endpoints) ;
420
+ merge_option ! ( config, env_config, apm_filter_tags_require) ;
421
+ merge_option ! ( config, env_config, apm_filter_tags_reject) ;
422
+ merge_option ! ( config, env_config, apm_filter_tags_regex_require) ;
423
+ merge_option ! ( config, env_config, apm_filter_tags_regex_reject) ;
391
424
merge_option_to_value ! ( config, env_config, trace_aws_service_representation_enabled) ;
392
425
393
426
// Trace Propagation
@@ -588,6 +621,16 @@ mod tests {
588
621
"enable_otlp_compute_top_level_by_span_kind,enable_stats_by_span_kind" ,
589
622
) ;
590
623
jail. set_env ( "DD_APM_ADDITIONAL_ENDPOINTS" , "{\" https://trace.agent.datadoghq.com\" : [\" apikey2\" , \" apikey3\" ], \" https://trace.agent.datadoghq.eu\" : [\" apikey4\" ]}" ) ;
624
+ jail. set_env ( "DD_APM_FILTER_TAGS_REQUIRE" , "env:production service:api" ) ;
625
+ jail. set_env ( "DD_APM_FILTER_TAGS_REJECT" , "debug:true env:test" ) ;
626
+ jail. set_env (
627
+ "DD_APM_FILTER_TAGS_REGEX_REQUIRE" ,
628
+ "env:^test.*$ debug:^true$" ,
629
+ ) ;
630
+ jail. set_env (
631
+ "DD_APM_FILTER_TAGS_REGEX_REJECT" ,
632
+ "env:^test.*$ debug:^true$" ,
633
+ ) ;
591
634
592
635
// Trace Propagation
593
636
jail. set_env ( "DD_TRACE_PROPAGATION_STYLE" , "datadog" ) ;
@@ -744,6 +787,22 @@ mod tests {
744
787
vec ! [ "apikey4" . to_string( ) ] ,
745
788
) ,
746
789
] ) ,
790
+ apm_filter_tags_require : Some ( vec ! [
791
+ "env:production" . to_string( ) ,
792
+ "service:api" . to_string( ) ,
793
+ ] ) ,
794
+ apm_filter_tags_reject : Some ( vec ! [
795
+ "debug:true" . to_string( ) ,
796
+ "env:test" . to_string( ) ,
797
+ ] ) ,
798
+ apm_filter_tags_regex_require : Some ( vec ! [
799
+ "env:^test.*$" . to_string( ) ,
800
+ "debug:^true$" . to_string( ) ,
801
+ ] ) ,
802
+ apm_filter_tags_regex_reject : Some ( vec ! [
803
+ "env:^test.*$" . to_string( ) ,
804
+ "debug:^true$" . to_string( ) ,
805
+ ] ) ,
747
806
trace_propagation_style : vec ! [ TracePropagationStyle :: Datadog ] ,
748
807
trace_propagation_style_extract : vec ! [ TracePropagationStyle :: B3 ] ,
749
808
trace_propagation_extract_first : true ,
0 commit comments