Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spans): only extract user.geo.subregion if mobile or frontend project #4013

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Remove the OTEL spans endpoint in favor of Envelopes. ([#3973](https://github.com/getsentry/relay/pull/3973))
- Remove the `generate-schema` tool. Relay no longer exposes JSON schema for the event protocol. Consult the Rust type documentation of the `relay-event-schema` crate instead. ([#3974](https://github.com/getsentry/relay/pull/3974))
- Allow creation of `SqliteEnvelopeBuffer` from config, and load existing stacks from db on startup. ([#3967](https://github.com/getsentry/relay/pull/3967))
- Only tag `user.geo.subregion` on frontend and mobile projects. ([#4013](https://github.com/getsentry/relay/pull/4013))

## 24.8.0

Expand Down
3 changes: 2 additions & 1 deletion relay-dynamic-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ pub fn hardcoded_span_metrics() -> Vec<(GroupKey, Vec<MetricSpec>, Vec<TagMappin
let is_app_start = RuleCondition::glob("span.op", "app.start.*")
& RuleCondition::eq("span.description", APP_START_ROOT_SPAN_DESCRIPTIONS);

let should_extract_geo = is_allowed_browser.clone() | is_mobile.clone() | is_resource.clone();
let should_extract_geo =
(is_allowed_browser.clone() & (is_resource.clone() | is_http.clone())) | is_mobile.clone();

// Metrics for addon modules are only extracted if the feature flag is enabled:
let is_addon = is_ai.clone() | is_queue_op.clone() | is_cache.clone();
Expand Down
74 changes: 69 additions & 5 deletions relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,18 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> {
if let Some(user_email) = user.email.value() {
tags.insert(SpanTagKey::UserEmail, user_email.clone());
}
if let Some(country_code) = user.geo.value().and_then(|geo| geo.country_code.value()) {
tags.insert(SpanTagKey::UserCountryCode, country_code.to_owned());
if let Some(subregion) = Subregion::from_iso2(country_code.as_str()) {
let numerical_subregion = subregion as u8;
tags.insert(SpanTagKey::UserSubregion, numerical_subregion.to_string());

// We only want this on frontend or mobile modules.
let should_extract_geo =
event.context::<BrowserContext>().is_some() || MOBILE_SDKS.contains(&event.sdk_name());

if should_extract_geo {
if let Some(country_code) = user.geo.value().and_then(|geo| geo.country_code.value()) {
tags.insert(SpanTagKey::UserCountryCode, country_code.to_owned());
if let Some(subregion) = Subregion::from_iso2(country_code.as_str()) {
let numerical_subregion = subregion as u8;
tags.insert(SpanTagKey::UserSubregion, numerical_subregion.to_string());
}
}
}
}
Expand Down Expand Up @@ -2676,6 +2683,9 @@ LIMIT 1
"trace": {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"span_id": "bd429c44b67a3eb4"
},
"browser": {
"name": "Chrome"
}
},
"user": {
Expand Down Expand Up @@ -2722,6 +2732,60 @@ LIMIT 1
assert_eq!(get_value!(span.sentry_tags["user.geo.subregion"]!), "21");
}

#[test]
fn not_extract_geo_location_if_not_browser() {
let json = r#"
{
"type": "transaction",
"platform": "python",
"start_timestamp": "2021-04-26T07:59:01+0100",
"timestamp": "2021-04-26T08:00:00+0100",
"transaction": "foo",
"contexts": {
"trace": {
"trace_id": "ff62a8b040f340bda5d830223def1d81",
"span_id": "bd429c44b67a3eb4"
}
},
"user": {
"id": "1",
"email": "admin@sentry.io",
"username": "admin",
"geo": {
"country_code": "US"
}
},
"spans": [
{
"op": "http.client",
"span_id": "bd429c44b67a3eb1",
"start_timestamp": 1597976300.0000000,
"timestamp": 1597976302.0000000,
"trace_id": "ff62a8b040f340bda5d830223def1d81"
}
]
}
"#;

let mut event = Annotated::<Event>::from_json(json).unwrap();

normalize_event(
&mut event,
&NormalizationConfig {
enrich_spans: true,
..Default::default()
},
);

let spans = get_value!(event.spans!);
let span = &spans[0];

let tags = span.value().unwrap().sentry_tags.value().unwrap();

assert_eq!(tags.get("user.geo.subregion"), None);
assert_eq!(tags.get("user.geo.country_code"), None);
}

#[test]
fn extract_thread_id_name_from_span_data_into_sentry_tags() {
let json = r#"
Expand Down
5 changes: 5 additions & 0 deletions relay-server/src/metrics_extraction/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ mod tests {
"span_id": "bd429c44b67a3eb4",
"op": "mYOp",
"status": "ok"
},
"browser": {
"name": "Chrome",
"version": "120.1.1",
"type": "browser"
}
},
"request": {
Expand Down
Loading
Loading