Skip to content

Commit b056a8e

Browse files
authored
Http url string obfuscation (#228)
1 parent 40398c4 commit b056a8e

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

src/config.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2023-Present Datadog, Inc.
33

44
use ddcommon::Endpoint;
5-
use log::{debug, error};
65
use std::borrow::Cow;
76
use std::env;
87
use std::str::FromStr;
98

10-
use datadog_trace_obfuscation::replacer::{self, ReplaceRule};
9+
use datadog_trace_obfuscation::obfuscation_config;
1110
use datadog_trace_utils::config_utils::{
1211
read_cloud_env, trace_intake_url, trace_intake_url_prefixed, trace_stats_url,
1312
trace_stats_url_prefixed,
@@ -29,7 +28,7 @@ pub struct Config {
2928
pub trace_intake: Endpoint,
3029
pub trace_stats_intake: Endpoint,
3130
pub dd_site: String,
32-
pub tag_replace_rules: Option<Vec<ReplaceRule>>,
31+
pub obfuscation_config: obfuscation_config::ObfuscationConfig,
3332
}
3433

3534
impl Config {
@@ -55,19 +54,11 @@ impl Config {
5554
trace_stats_intake_url = trace_stats_url_prefixed(&endpoint_prefix);
5655
};
5756

58-
let tag_replace_rules: Option<Vec<ReplaceRule>> = match env::var("DD_APM_REPLACE_TAGS") {
59-
Ok(replace_rules_str) => match replacer::parse_rules_from_string(&replace_rules_str) {
60-
Ok(res) => {
61-
debug!("Successfully parsed DD_APM_REPLACE_TAGS: {res:?}");
62-
Some(res)
63-
}
64-
Err(e) => {
65-
error!("Failed to parse DD_APM_REPLACE_TAGS: {e}");
66-
None
67-
}
68-
},
69-
Err(_) => None,
70-
};
57+
let obfuscation_config = obfuscation_config::ObfuscationConfig::new().map_err(|err| {
58+
anyhow::anyhow!(
59+
"Error creating obfuscation config, Mini Agent will not start. Error: {err}",
60+
)
61+
})?;
7162

7263
Ok(Config {
7364
function_name: Some(function_name),
@@ -86,7 +77,7 @@ impl Config {
8677
url: hyper::Uri::from_str(&trace_stats_intake_url).unwrap(),
8778
api_key: Some(api_key),
8879
},
89-
tag_replace_rules,
80+
obfuscation_config,
9081
})
9182
}
9283
}

src/trace_processor.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hyper::{http, Body, Request, Response, StatusCode};
88
use log::info;
99
use tokio::sync::mpsc::Sender;
1010

11-
use datadog_trace_obfuscation::replacer;
11+
use datadog_trace_obfuscation::obfuscate::obfuscate_span;
1212
use datadog_trace_utils::trace_utils;
1313
use datadog_trace_utils::trace_utils::SendData;
1414

@@ -76,10 +76,7 @@ impl TraceProcessor for ServerlessTraceProcessor {
7676
);
7777
for span in chunk.spans.iter_mut() {
7878
trace_utils::enrich_span_with_mini_agent_metadata(span, &mini_agent_metadata);
79-
}
80-
81-
if let Some(rules) = &config.tag_replace_rules {
82-
replacer::replace_trace_tags(&mut chunk.spans, rules)
79+
obfuscate_span(span, &config.obfuscation_config);
8380
}
8481
},
8582
);
@@ -106,6 +103,7 @@ impl TraceProcessor for ServerlessTraceProcessor {
106103

107104
#[cfg(test)]
108105
mod tests {
106+
use datadog_trace_obfuscation::obfuscation_config::ObfuscationConfig;
109107
use hyper::Request;
110108
use std::{
111109
collections::HashMap,
@@ -150,7 +148,7 @@ mod tests {
150148
dd_site: "datadoghq.com".to_string(),
151149
env_type: trace_utils::EnvironmentType::CloudFunction,
152150
os: "linux".to_string(),
153-
tag_replace_rules: None,
151+
obfuscation_config: ObfuscationConfig::new().unwrap(),
154152
}
155153
}
156154

0 commit comments

Comments
 (0)