Skip to content

Commit f18bca9

Browse files
committed
add global config allowed hosts to http attribute normalization
1 parent 3dfa808 commit f18bca9

File tree

2 files changed

+60
-8
lines changed
  • relay-event-normalization/src/eap
  • relay-server/src/processing/spans

2 files changed

+60
-8
lines changed

relay-event-normalization/src/eap/mod.rs

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,12 @@ fn normalize_attribute_names_inner(
280280
/// however, V2 spans now store these values in their respective attributes based on sentry conventions.
281281
/// This function ports over the SpanV1 normalization logic that was previously in `scrub_span_description`
282282
/// by creating a set of functions to handle each group of attributes separately.
283-
pub fn normalize_attribute_values(attributes: &mut Annotated<Attributes>) {
283+
pub fn normalize_attribute_values(
284+
attributes: &mut Annotated<Attributes>,
285+
http_span_allowed_hosts: &[String],
286+
) {
284287
normalize_db_attributes(attributes);
285-
normalize_http_attributes(attributes);
288+
normalize_http_attributes(attributes, http_span_allowed_hosts);
286289
}
287290

288291
/// Normalizes the following db attributes: `db.query.text`, `db.operation.name`, `db.collection.name`
@@ -412,7 +415,10 @@ fn normalize_db_attributes(annotated_attributes: &mut Annotated<Attributes>) {
412415
///
413416
/// The normalization process first scrubs the url and extracts the server address from the url.
414417
/// It also sets 'url.full' to the raw url if it is not already set and can be retrieved from the server address.
415-
fn normalize_http_attributes(annotated_attributes: &mut Annotated<Attributes>) {
418+
fn normalize_http_attributes(
419+
annotated_attributes: &mut Annotated<Attributes>,
420+
allowed_hosts: &[String],
421+
) {
416422
let Some(attributes) = annotated_attributes.value() else {
417423
return;
418424
};
@@ -442,7 +448,7 @@ fn normalize_http_attributes(annotated_attributes: &mut Annotated<Attributes>) {
442448
let (normalized_server_address, raw_url) = if op == Some("http.client") {
443449
let domain_from_scrubbed_http = method
444450
.zip(url)
445-
.and_then(|(method, url)| scrub_http(method, url, &[]))
451+
.and_then(|(method, url)| scrub_http(method, url, allowed_hosts))
446452
.and_then(|scrubbed_http| domain_from_scrubbed_http(&scrubbed_http));
447453

448454
if let Some(domain) = domain_from_scrubbed_http {
@@ -1214,7 +1220,7 @@ mod tests {
12141220
)
12151221
.unwrap();
12161222

1217-
normalize_http_attributes(&mut attributes);
1223+
normalize_http_attributes(&mut attributes, &[]);
12181224

12191225
insta::assert_json_snapshot!(SerializableAnnotated(&attributes), @r#"
12201226
{
@@ -1264,7 +1270,7 @@ mod tests {
12641270
)
12651271
.unwrap();
12661272

1267-
normalize_http_attributes(&mut attributes);
1273+
normalize_http_attributes(&mut attributes, &[]);
12681274

12691275
insta::assert_json_snapshot!(SerializableAnnotated(&attributes), @r#"
12701276
{
@@ -1291,4 +1297,50 @@ mod tests {
12911297
}
12921298
"#);
12931299
}
1300+
1301+
#[test]
1302+
fn test_normalize_http_attributes_allowed_hosts() {
1303+
let mut attributes = Annotated::<Attributes>::from_json(
1304+
r#"
1305+
{
1306+
"sentry.op": {
1307+
"type": "string",
1308+
"value": "http.client"
1309+
},
1310+
"http.request.method": {
1311+
"type": "string",
1312+
"value": "GET"
1313+
},
1314+
"url.full": {
1315+
"type": "string",
1316+
"value": "http://192.168.1.1:3000"
1317+
}
1318+
}
1319+
"#,
1320+
)
1321+
.unwrap();
1322+
1323+
normalize_http_attributes(&mut attributes, &["192.168.1.1".to_owned()]);
1324+
1325+
insta::assert_json_snapshot!(SerializableAnnotated(&attributes), @r#"
1326+
{
1327+
"http.request.method": {
1328+
"type": "string",
1329+
"value": "GET"
1330+
},
1331+
"sentry.op": {
1332+
"type": "string",
1333+
"value": "http.client"
1334+
},
1335+
"server.address": {
1336+
"type": "string",
1337+
"value": "192.168.1.1:3000"
1338+
},
1339+
"url.full": {
1340+
"type": "string",
1341+
"value": "http://192.168.1.1:3000"
1342+
}
1343+
}
1344+
"#);
1345+
}
12941346
}

relay-server/src/processing/spans/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ fn normalize_span(
151151
let dsc = headers.dsc();
152152
let duration = span_duration(span);
153153
let model_costs = ctx.global_config.ai_model_costs.as_ref().ok();
154+
let allowed_hosts = ctx.global_config.options.http_span_allowed_hosts.as_slice();
154155

155156
validate_timestamps(span)?;
156157

@@ -167,8 +168,7 @@ fn normalize_span(
167168
eap::normalize_dsc(&mut span.attributes, dsc);
168169
}
169170
eap::normalize_ai(&mut span.attributes, duration, model_costs);
170-
171-
eap::normalize_attribute_values(&mut span.attributes);
171+
eap::normalize_attribute_values(&mut span.attributes, allowed_hosts);
172172
};
173173

174174
process_value(span, &mut TrimmingProcessor::new(), ProcessingState::root())?;

0 commit comments

Comments
 (0)