Skip to content

Commit 70c15da

Browse files
authored
feat(spans): extract country code into spans (#3911)
work towards getsentry/sentry#75230 This PR adds country_code as an indexed span tag. Eventually we would like to create regional metrics, but we have to make a product decision on whether we want country based metrics, or larger region metrics (ex. continent). There are also ~200 countries, which could be high cardinality wise, but at least we have a known limit (lmk if you have thoughts on this!)
1 parent 5e3cf56 commit 70c15da

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Collect SDK information in profile chunks. ([#3882](https://github.com/getsentry/relay/pull/3882))
1818
- Introduce `trim = "disabled"` type attribute to prevent trimming of spans. ([#3877](https://github.com/getsentry/relay/pull/3877))
1919
- Make the tcp listen backlog configurable and raise the default to 1024. ([#3899](https://github.com/getsentry/relay/pull/3899))
20+
- Extract `user.geo.country_code` into span indexed. ([#3911](https://github.com/getsentry/relay/pull/3911))
2021

2122
## 24.7.1
2223

@@ -48,6 +49,7 @@
4849
- Only transfer valid profile ids. ([#3809](https://github.com/getsentry/relay/pull/3809))
4950

5051
**Features**:
52+
5153
- Allow list for excluding certain host/IPs from scrubbing in spans. ([#3813](https://github.com/getsentry/relay/pull/3813))
5254

5355
**Internal**:

relay-event-normalization/src/normalize/span/tag_extraction.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub enum SpanTagKey {
8585
ThreadName,
8686
ThreadId,
8787
ProfilerId,
88+
UserCountryCode,
8889
}
8990

9091
impl SpanTagKey {
@@ -98,6 +99,7 @@ impl SpanTagKey {
9899
SpanTagKey::UserID => "user.id",
99100
SpanTagKey::UserUsername => "user.username",
100101
SpanTagKey::UserEmail => "user.email",
102+
SpanTagKey::UserCountryCode => "user.geo.country_code",
101103
SpanTagKey::Environment => "environment",
102104
SpanTagKey::Transaction => "transaction",
103105
SpanTagKey::TransactionMethod => "transaction.method",
@@ -308,6 +310,9 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> {
308310
if let Some(user_email) = user.email.value() {
309311
tags.insert(SpanTagKey::UserEmail, user_email.clone());
310312
}
313+
if let Some(country_code) = user.geo.value().and_then(|geo| geo.country_code.value()) {
314+
tags.insert(SpanTagKey::UserCountryCode, country_code.to_owned());
315+
}
311316
}
312317

313318
if let Some(environment) = event.environment.as_str() {
@@ -2537,7 +2542,10 @@ LIMIT 1
25372542
"user": {
25382543
"id": "1",
25392544
"email": "[email protected]",
2540-
"username": "admin"
2545+
"username": "admin",
2546+
"geo": {
2547+
"country_code": "US"
2548+
}
25412549
},
25422550
"spans": [
25432551
{
@@ -2571,6 +2579,7 @@ LIMIT 1
25712579
get_value!(span.sentry_tags["user.email"]!),
25722580
25732581
);
2582+
assert_eq!(get_value!(span.sentry_tags["user.geo.country_code"]!), "US");
25742583
}
25752584

25762585
#[test]

0 commit comments

Comments
 (0)