@@ -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}
0 commit comments