Skip to content

Commit f74dfb0

Browse files
authored
fix(unreal): Fix unreal crash reporter OS names, improve os name parsing (#4854)
Fixes: #4834
1 parent 8f4316a commit f74dfb0

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
**Bug Fixes**:
6+
7+
- OS name parsing of Unreal crash reports. ([#4854](https://github.com/getsentry/relay/pull/4854))
8+
59
**Internal**:
610

711
- Forward logs to Kafka directly instead of serialized as envelope. ([#4875](https://github.com/getsentry/relay/pull/4875))

relay-event-normalization/src/normalize/contexts.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use relay_protocol::{Annotated, Empty, Value};
1111

1212
/// Environment.OSVersion (GetVersionEx) or RuntimeInformation.OSDescription on Windows
1313
static OS_WINDOWS_REGEX1: Lazy<Regex> = Lazy::new(|| {
14-
Regex::new(r"^(Microsoft )?Windows (NT )?(?P<version>\d+\.\d+\.(?P<build_number>\d+)).*$")
14+
Regex::new(r"^(Microsoft\s+)?Windows\s+(NT\s+)?(?P<version>\d+\.\d+\.(?P<build_number>\d+)).*$")
1515
.unwrap()
1616
});
1717
static OS_WINDOWS_REGEX2: Lazy<Regex> = Lazy::new(|| {
@@ -179,6 +179,28 @@ fn get_windows_version(description: &str) -> Option<(&str, &str)> {
179179
Some((version_name, build_number_str))
180180
}
181181

182+
/// Simple marketing names in the form `<OS> <version>`.
183+
fn get_marketing_name(description: &str) -> Option<(&str, &str)> {
184+
let (name, version) = description.split_once(' ')?;
185+
let name = name.trim();
186+
let version = version.trim();
187+
188+
// Validate if it looks like a reasonable name.
189+
if name.bytes().any(|c| !c.is_ascii_alphabetic()) {
190+
return None;
191+
}
192+
193+
// Validate if it looks like a reasonable version.
194+
if version
195+
.bytes()
196+
.any(|c| !matches!(c, b'0'..=b'9' | b'.' | b'-'))
197+
{
198+
return None;
199+
}
200+
201+
Some((name, version))
202+
}
203+
182204
#[allow(dead_code)]
183205
/// Returns the API version of an Android description.
184206
///
@@ -221,20 +243,12 @@ fn normalize_os_context(os: &mut OsContext) {
221243
.name("version")
222244
.map(|m| m.as_str().to_owned())
223245
.into();
224-
os.build = captures
225-
.name("build")
226-
.map(|m| m.as_str().to_owned().into())
227-
.into();
228246
} else if let Some(captures) = OS_IPADOS_REGEX.captures(raw_description) {
229247
os.name = "iPadOS".to_owned().into();
230248
os.version = captures
231249
.name("version")
232250
.map(|m| m.as_str().to_owned())
233251
.into();
234-
os.build = captures
235-
.name("build")
236-
.map(|m| m.as_str().to_owned().into())
237-
.into();
238252
} else if let Some(captures) = OS_LINUX_DISTRO_UNAME_REGEX.captures(raw_description) {
239253
os.name = captures.name("name").map(|m| m.as_str().to_owned()).into();
240254
os.version = captures
@@ -259,6 +273,9 @@ fn normalize_os_context(os: &mut OsContext) {
259273
.into();
260274
} else if raw_description == "Nintendo Switch" {
261275
os.name = "Nintendo OS".to_owned().into();
276+
} else if let Some((name, version)) = get_marketing_name(raw_description) {
277+
os.name = name.to_owned().into();
278+
os.version = version.to_owned().into();
262279
}
263280
}
264281

@@ -732,6 +749,17 @@ mod tests {
732749
assert_eq!(Some("30"), get_android_api_version(description));
733750
}
734751

752+
#[test]
753+
fn test_unreal_windows_os() {
754+
let mut os = OsContext {
755+
raw_description: "Windows 10".to_owned().into(),
756+
..OsContext::default()
757+
};
758+
normalize_os_context(&mut os);
759+
assert_eq!(Some("Windows"), os.name.as_str());
760+
assert_eq!(Some("10"), os.version.as_str());
761+
}
762+
735763
#[test]
736764
fn test_linux_5_11() {
737765
let mut os = OsContext {

relay-server/src/utils/snapshots/relay_server__utils__unreal__tests__merge_unreal_context.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ expression: "Annotated::new(event).to_json_pretty().unwrap()"
2424
"type": "gpu"
2525
},
2626
"os": {
27-
"name": "Windows 10",
27+
"raw_description": "Windows 10",
2828
"type": "os"
2929
},
3030
"unreal": {

relay-server/src/utils/snapshots/relay_server__utils__unreal__tests__merge_unreal_context_event.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ expression: "Annotated::new(event).to_json_pretty().unwrap()"
2020
"type": "gpu"
2121
},
2222
"os": {
23-
"name": "Windows 10",
23+
"raw_description": "Windows 10",
2424
"type": "os"
2525
},
2626
"unreal": {

relay-server/src/utils/unreal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn merge_unreal_context(event: &mut Event, context: Unreal4Context) {
238238
// OS information is likely overwritten by Minidump processing later.
239239
if let Some(os_major) = runtime_props.misc_os_version_major.take() {
240240
let os_context = contexts.get_or_default::<OsContext>();
241-
os_context.name = Annotated::new(os_major);
241+
os_context.raw_description = Annotated::new(os_major);
242242
}
243243

244244
// See https://github.com/EpicGames/UnrealEngine/blob/5.3.2-release/Engine/Source/Runtime/RHI/Private/DynamicRHI.cpp#L368-L376

0 commit comments

Comments
 (0)