Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
Some(match iso2_letter {
Expand Down
16 changes: 10 additions & 6 deletions relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions relay-spans/src/v1_to_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -483,7 +483,7 @@ mod tests {
},
"sentry.user.geo.subregion": {
"type": "string",
"value": "155"
"value": "Western Europe"
},
"sentry.user.id": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_pii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
Loading