Skip to content

Commit

Permalink
collect geo data on appropriate transaction metrics too
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikB2014 committed Aug 12, 2024
1 parent 7fc457c commit 239a9a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion relay-server/src/metrics_extraction/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::{BTreeMap, BTreeSet};
use relay_base_schema::events::EventType;
use relay_common::time::UnixTimestamp;
use relay_dynamic_config::{CombinedMetricExtractionConfig, TransactionMetricsConfig};
use relay_event_normalization::span::country_subregion::Subregion;
use relay_event_normalization::utils as normalize_utils;
use relay_event_schema::protocol::{
AsPair, BrowserContext, Event, OsContext, PerformanceScoreContext, TraceContext,
Expand All @@ -29,10 +30,11 @@ const PLACEHOLDER_UNPARAMETERIZED: &str = "<< unparameterized >>";
/// Tags we set on metrics for performance score measurements (e.g. `score.lcp.weight`).
///
/// These are a subset of "universal" tags.
const PERFORMANCE_SCORE_TAGS: [CommonTag; 6] = [
const PERFORMANCE_SCORE_TAGS: [CommonTag; 7] = [
CommonTag::BrowserName,
CommonTag::Environment,
CommonTag::GeoCountryCode,
CommonTag::UserSubregion,
CommonTag::Release,
CommonTag::Transaction,
CommonTag::TransactionOp,
Expand Down Expand Up @@ -193,6 +195,16 @@ fn extract_universal_tags(event: &Event, config: &TransactionMetricsConfig) -> C
tags.insert(CommonTag::GeoCountryCode, geo_country_code);
}

// The product only uses the subregion for web data at the moment
if let Some(_browser_name) = extract_browser_name(event) {
if let Some(geo_country_code) = extract_geo_country_code(event) {
if let Some(subregion) = Subregion::from_iso2(geo_country_code.as_str()) {
let numerical_subregion = subregion as u8;
tags.insert(CommonTag::UserSubregion, numerical_subregion.to_string());
}
}
}

if let Some(status_code) = normalize_utils::extract_http_status_code(event) {
tags.insert(CommonTag::HttpStatusCode, status_code);
}
Expand Down Expand Up @@ -672,6 +684,7 @@ mod tests {
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"transaction.status": "ok",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -706,6 +719,7 @@ mod tests {
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"transaction.status": "ok",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -734,6 +748,7 @@ mod tests {
"sentry.score_profile_version": "alpha",
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -762,6 +777,7 @@ mod tests {
"sentry.score_profile_version": "alpha",
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -790,6 +806,7 @@ mod tests {
"sentry.score_profile_version": "alpha",
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -823,6 +840,7 @@ mod tests {
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"transaction.status": "ok",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -874,6 +892,7 @@ mod tests {
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"transaction.status": "ok",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down Expand Up @@ -930,6 +949,7 @@ mod tests {
"transaction": "gEt /api/:version/users/",
"transaction.op": "mYOp",
"transaction.status": "ok",
"user.geo.subregion": "21",
},
metadata: BucketMetadata {
merges: 1,
Expand Down
2 changes: 2 additions & 0 deletions relay-server/src/metrics_extraction/transactions/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pub enum CommonTag {
BrowserName,
OsName,
GeoCountryCode,
UserSubregion,
DeviceClass,
Custom(String),
}
Expand All @@ -251,6 +252,7 @@ impl Display for CommonTag {
CommonTag::BrowserName => "browser.name",
CommonTag::OsName => "os.name",
CommonTag::GeoCountryCode => "geo.country_code",
CommonTag::UserSubregion => "user.geo.subregion",
CommonTag::DeviceClass => "device.class",
CommonTag::Custom(s) => s,
};
Expand Down

0 comments on commit 239a9a4

Please sign in to comment.