Skip to content

Commit 5abf32b

Browse files
committed
perf: pre-compile APM tag regex filters at startup
Compile DD_APM_FILTER_TAGS_REGEX_REQUIRE and DD_APM_FILTER_TAGS_REGEX_REJECT patterns once at startup into a RegexFilter struct { key, regex: Option<Regex> } rather than re-parsing and compiling on every span.
1 parent 672f268 commit 5abf32b

4 files changed

Lines changed: 294 additions & 133 deletions

File tree

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,9 +1134,10 @@ fn start_trace_agent(
11341134
obfuscation_redis_remove_all_args: false,
11351135
};
11361136

1137-
let trace_processor = Arc::new(trace_processor::ServerlessTraceProcessor {
1138-
obfuscation_config: Arc::new(obfuscation_config),
1139-
});
1137+
let trace_processor = Arc::new(trace_processor::ServerlessTraceProcessor::new(
1138+
config.as_ref(),
1139+
obfuscation_config,
1140+
));
11401141

11411142
let (span_dedup_service, span_dedup_handle) = span_dedup_service::DedupService::new();
11421143
tokio::spawn(span_dedup_service.run());

bottlecap/src/config/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub struct EnvConfig {
226226
/// @env `DD_APM_FILTER_TAGS_REQUIRE`
227227
///
228228
/// Space-separated list of key:value tag pairs that spans must match to be kept.
229-
/// Only spans matching at least one of these tags will be sent to Datadog.
229+
/// Only spans matching all of these tags will be sent to Datadog.
230230
/// Example: "env:production service:api-gateway"
231231
#[serde(deserialize_with = "deserialize_apm_filter_tags")]
232232
pub apm_filter_tags_require: Option<Vec<String>>,
@@ -240,7 +240,7 @@ pub struct EnvConfig {
240240
/// @env `DD_APM_FILTER_TAGS_REGEX_REQUIRE`
241241
///
242242
/// Space-separated list of key:value tag pairs with regex values that spans must match to be kept.
243-
/// Only spans matching at least one of these regex patterns will be sent to Datadog.
243+
/// Only spans matching all of these regex patterns will be sent to Datadog.
244244
/// Example: "env:^prod.*$ service:^api-.*$"
245245
#[serde(deserialize_with = "deserialize_apm_filter_tags")]
246246
pub apm_filter_tags_regex_require: Option<Vec<String>>,

bottlecap/src/lifecycle/invocation/processor.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,9 +1671,11 @@ mod tests {
16711671
// Create trace sender
16721672
let trace_sender = Arc::new(SendingTraceProcessor {
16731673
appsec: None,
1674-
processor: Arc::new(trace_processor::ServerlessTraceProcessor {
1675-
obfuscation_config: Arc::new(ObfuscationConfig::new().expect("Failed to create ObfuscationConfig")),
1676-
}),
1674+
processor: Arc::new(trace_processor::ServerlessTraceProcessor::new(
1675+
config.as_ref(),
1676+
ObfuscationConfig::new()
1677+
.expect("Failed to create ObfuscationConfig"),
1678+
)),
16771679
trace_tx: tokio::sync::mpsc::channel(1).0,
16781680
stats_generator: Arc::new(StatsGenerator::new(stats_concentrator_handle)),
16791681
});
@@ -1779,11 +1781,10 @@ mod tests {
17791781
tokio::spawn(stats_concentrator_service.run());
17801782
let trace_sender = Arc::new(SendingTraceProcessor {
17811783
appsec: None,
1782-
processor: Arc::new(trace_processor::ServerlessTraceProcessor {
1783-
obfuscation_config: Arc::new(
1784-
ObfuscationConfig::new().expect("Failed to create ObfuscationConfig"),
1785-
),
1786-
}),
1784+
processor: Arc::new(trace_processor::ServerlessTraceProcessor::new(
1785+
config.as_ref(),
1786+
ObfuscationConfig::new().expect("Failed to create ObfuscationConfig"),
1787+
)),
17871788
trace_tx: tokio::sync::mpsc::channel(1).0,
17881789
stats_generator: Arc::new(StatsGenerator::new(stats_concentrator_handle)),
17891790
});
@@ -2174,11 +2175,10 @@ mod tests {
21742175
tokio::spawn(stats_concentrator_service.run());
21752176
let trace_sender = Arc::new(SendingTraceProcessor {
21762177
appsec: None,
2177-
processor: Arc::new(trace_processor::ServerlessTraceProcessor {
2178-
obfuscation_config: Arc::new(
2179-
ObfuscationConfig::new().expect("Failed to create ObfuscationConfig"),
2180-
),
2181-
}),
2178+
processor: Arc::new(trace_processor::ServerlessTraceProcessor::new(
2179+
config.as_ref(),
2180+
ObfuscationConfig::new().expect("Failed to create ObfuscationConfig"),
2181+
)),
21822182
trace_tx,
21832183
stats_generator: Arc::new(StatsGenerator::new(stats_concentrator_handle)),
21842184
});

0 commit comments

Comments
 (0)