diff --git a/relay-event-normalization/src/normalize/span/country_subregion.rs b/relay-event-normalization/src/normalize/span/country_subregion.rs index 0d347c84faf..4456fd38dec 100644 --- a/relay-event-normalization/src/normalize/span/country_subregion.rs +++ b/relay-event-normalization/src/normalize/span/country_subregion.rs @@ -29,6 +29,34 @@ pub enum Subregion { } impl Subregion { + /// Returns the human-readable name of the subregion. + pub fn as_str(&self) -> &'static str { + match self { + Subregion::NorthernAmerica => "Northern America", + Subregion::CentralAmerica => "Central America", + Subregion::Caribbean => "Caribbean", + Subregion::SouthAmerica => "South America", + Subregion::NorthernEurope => "Northern Europe", + Subregion::WesternEurope => "Western Europe", + Subregion::SouthernEurope => "Southern Europe", + Subregion::EasternEurope => "Eastern Europe", + Subregion::EasternAsia => "Eastern Asia", + Subregion::SouthernAsia => "Southern Asia", + Subregion::SouthEasternAsia => "South-Eastern Asia", + Subregion::WesternAsia => "Western Asia", + Subregion::CentralAsia => "Central Asia", + Subregion::NorthernAfrica => "Northern Africa", + Subregion::WesternAfrica => "Western Africa", + Subregion::MiddleAfrica => "Middle Africa", + Subregion::EasternAfrica => "Eastern Africa", + Subregion::SouthernAfrica => "Southern Africa", + Subregion::Melanesia => "Melanesia", + Subregion::Micronesia => "Micronesia", + Subregion::Polynesia => "Polynesia", + Subregion::AustraliaAndNewZealand => "Australia and New Zealand", + } + } + /// Maps 2 ISO letter country codes to geoscheme regions based on the UN M.49 standard. pub fn from_iso2(iso2_letter: &str) -> Option { Some(match iso2_letter { diff --git a/relay-event-normalization/src/normalize/span/tag_extraction.rs b/relay-event-normalization/src/normalize/span/tag_extraction.rs index 08cad01fade..6db30003164 100644 --- a/relay-event-normalization/src/normalize/span/tag_extraction.rs +++ b/relay-event-normalization/src/normalize/span/tag_extraction.rs @@ -353,8 +353,7 @@ fn extract_shared_tags(event: &Event) -> SharedTags { if let Some(country_code) = geo.country_code.value() { tags.user_country_code = country_code.clone().into(); if let Some(subregion) = Subregion::from_iso2(country_code.as_str()) { - let numerical_subregion = subregion as u8; - tags.user_subregion = numerical_subregion.to_string().into(); + tags.user_subregion = subregion.as_str().to_owned().into(); } } @@ -1078,8 +1077,7 @@ pub fn extract_tags( { span_tags.user_country_code = country_code.to_owned().into(); if let Some(subregion) = Subregion::from_iso2(country_code.as_str()) { - let numerical_subregion = subregion as u8; - span_tags.user_subregion = numerical_subregion.to_string().into(); + span_tags.user_subregion = subregion.as_str().to_owned().into(); } } } @@ -3226,7 +3224,10 @@ LIMIT 1 assert_eq!(get_value!(span.sentry_tags.user_city!), "Vienna"); assert_eq!(get_value!(span.sentry_tags.user_region!), "Austria"); assert_eq!(get_value!(span.sentry_tags.user_subdivision!), "Vienna"); - assert_eq!(get_value!(span.sentry_tags.user_subregion!), "155"); + assert_eq!( + get_value!(span.sentry_tags.user_subregion!), + "Western Europe" + ); } #[test] @@ -3451,7 +3452,10 @@ LIMIT 1 let tags = extract_tags(&span, 200, None, None, false, None, &[], &lookup); assert_eq!(tags.user_country_code.value(), Some(&"GB".to_owned())); - assert_eq!(tags.user_subregion.value(), Some(&"154".to_owned())); + assert_eq!( + tags.user_subregion.value(), + Some(&"Northern Europe".to_owned()) + ); } #[test] diff --git a/relay-spans/src/v1_to_v2.rs b/relay-spans/src/v1_to_v2.rs index c3d5a36f3d2..7eed9823284 100644 --- a/relay-spans/src/v1_to_v2.rs +++ b/relay-spans/src/v1_to_v2.rs @@ -333,7 +333,7 @@ mod tests { "user.geo.country_code": "AT", "user.geo.region": "Europe", "user.geo.subdivision": "AT-9", - "user.geo.subregion": "155", + "user.geo.subregion": "Western Europe", "user.id": "user123", "user.ip": "127.0.0.1", "user.username": "john", @@ -483,7 +483,7 @@ mod tests { }, "sentry.user.geo.subregion": { "type": "string", - "value": "155" + "value": "Western Europe" }, "sentry.user.id": { "type": "string", diff --git a/tests/integration/test_pii.py b/tests/integration/test_pii.py index 61802641004..d54b15ce08d 100644 --- a/tests/integration/test_pii.py +++ b/tests/integration/test_pii.py @@ -36,7 +36,7 @@ def test_scrub_span_sentry_tags_advanced_rules(mini_sentry, relay): event = mini_sentry.get_captured_envelope().get_event() assert event["spans"][0]["sentry_tags"]["user.geo.country_code"] == "**" - assert event["spans"][0]["sentry_tags"]["user.geo.subregion"] == "***" + assert event["spans"][0]["sentry_tags"]["user.geo.subregion"] == "***************" @pytest.mark.parametrize( diff --git a/tests/integration/test_spans.py b/tests/integration/test_spans.py index 7e2f6832a88..4846d6e65e9 100644 --- a/tests/integration/test_spans.py +++ b/tests/integration/test_spans.py @@ -152,7 +152,7 @@ def test_span_extraction( "sentry.user.geo.country_code": {"type": "string", "value": "AT"}, "sentry.user.geo.region": {"type": "string", "value": "Austria"}, "sentry.user.geo.subdivision": {"type": "string", "value": "Vienna"}, - "sentry.user.geo.subregion": {"type": "string", "value": "155"}, + "sentry.user.geo.subregion": {"type": "string", "value": "Western Europe"}, "sentry.user.id": {"type": "string", "value": user_id}, "sentry.user.ip": {"type": "string", "value": "192.168.0.1"}, "user.geo.city": {"type": "string", "value": "Vienna"}, @@ -245,7 +245,7 @@ def test_span_extraction( "sentry.user.geo.country_code": {"type": "string", "value": "AT"}, "sentry.user.geo.region": {"type": "string", "value": "Austria"}, "sentry.user.geo.subdivision": {"type": "string", "value": "Vienna"}, - "sentry.user.geo.subregion": {"type": "string", "value": "155"}, + "sentry.user.geo.subregion": {"type": "string", "value": "Western Europe"}, "sentry.user.id": {"type": "string", "value": user_id}, "sentry.user.ip": {"type": "string", "value": "192.168.0.1"}, "user.geo.city": {"type": "string", "value": "Vienna"},