Skip to content

Commit

Permalink
fix: Normalize "Google Chrome" to "Chrome" (#4386)
Browse files Browse the repository at this point in the history
The Chrome browser is sometimes tagged as "Google Chrome" and sometimes
just "Chrome". This unifies the two into the latter.
  • Loading branch information
loewenheim authored Dec 18, 2024
1 parent b3ecbb9 commit 18cc3ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Update user agent parsing rules to fix some user agent identification issues. ([#4385](https://github.com/getsentry/relay/pull/4385))
- Stop collecting the `has_profile` metrics tag & reporting outcomes for it. ([#4365](https://github.com/getsentry/relay/pull/4365))
- Parse unreal logs into breadcrumbs from all attached log items not just the first. ([#4384](https://github.com/getsentry/relay/pull/4384))
- Normalize "Google Chrome" browser name to "Chrome". ([#4386](https://github.com/getsentry/relay/pull/4386))

**Features**:

Expand Down
16 changes: 13 additions & 3 deletions relay-event-normalization/src/normalize/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ impl FromUserAgentInfo for DeviceContext {

impl FromUserAgentInfo for BrowserContext {
fn parse_client_hints(client_hints: &ClientHints<&str>) -> Option<Self> {
let (browser, version) = browser_from_client_hints(client_hints.sec_ch_ua?)?;
let (mut browser, version) = browser_from_client_hints(client_hints.sec_ch_ua?)?;

// Normalize "Google Chrome" to just "Chrome"
if browser == "Google Chrome" {
browser = "Chrome".to_owned();
}

Some(Self {
name: Annotated::new(browser),
Expand All @@ -342,12 +347,17 @@ impl FromUserAgentInfo for BrowserContext {
}

fn parse_user_agent(user_agent: &str) -> Option<Self> {
let browser = relay_ua::parse_user_agent(user_agent);
let mut browser = relay_ua::parse_user_agent(user_agent);

if !is_known(&browser.family) {
return None;
}

// Normalize "Google Chrome" to just "Chrome"
if browser.family == "Google Chrome" {
browser.family = "Chrome".into();
}

Some(Self {
name: Annotated::from(browser.family.into_owned()),
version: Annotated::from(get_version(&browser.major, &browser.minor, &browser.patch)),
Expand Down Expand Up @@ -824,7 +834,7 @@ mod tests {
insta::assert_debug_snapshot!(browser, @r###"
BrowserContext {
browser: ~,
name: "Google Chrome",
name: "Chrome",
version: "109",
other: {},
}
Expand Down

0 comments on commit 18cc3ce

Please sign in to comment.