Skip to content

Commit d232836

Browse files
feat: Make default Apple device class high (#4609)
Change the default device class to high for iPhones and iPads. We have an extensive list of these devices, which are well-known. If a device is not on this list, it must be a new one. Previously, we set the device class to unknown until we manually update this list. Now, the default is high. This came up while investigating getsentry/sentry#68258.
1 parent 9f4f27c commit d232836

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Filter out certain AI crawlers. ([#4608](https://github.com/getsentry/relay/pull/4608))
1111
- Update iOS chrome translation error regex. ([#4634](https://github.com/getsentry/relay/pull/4634))
1212
- Infer the attachment type of view hierarchy items in multipart messages. ([#4624](https://github.com/getsentry/relay/pull/4624))
13+
- Make default Apple device class high. ([#4609](https://github.com/getsentry/relay/pull/4609))
1314

1415
**Bug Fixes**:
1516

relay-event-schema/src/protocol/device_class.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,79 @@ fn model_to_class(model: &str) -> Option<DeviceClass> {
200200
"iPad16,5" => Some(DeviceClass::HIGH),
201201
"iPad16,6" => Some(DeviceClass::HIGH),
202202

203-
_ => None,
203+
// If we don't know the model it's a new device and therefore must be high.
204+
_ => Some(DeviceClass::HIGH),
205+
}
206+
}
207+
208+
#[cfg(test)]
209+
mod tests {
210+
use super::*;
211+
212+
#[test]
213+
fn test_iphone17_5_returns_device_class_high() {
214+
let mut contexts = Contexts::new();
215+
contexts.add(DeviceContext {
216+
family: Annotated::new("iOS".to_string()),
217+
model: Annotated::new("iPhone17,5".to_string()),
218+
..DeviceContext::default()
219+
});
220+
assert_eq!(
221+
DeviceClass::from_contexts(&contexts),
222+
Some(DeviceClass::HIGH)
223+
);
224+
}
225+
226+
#[test]
227+
fn test_iphone99_1_returns_device_class_high() {
228+
let mut contexts = Contexts::new();
229+
contexts.add(DeviceContext {
230+
family: Annotated::new("iOS".to_string()),
231+
model: Annotated::new("iPhone99,1".to_string()),
232+
..DeviceContext::default()
233+
});
234+
assert_eq!(
235+
DeviceClass::from_contexts(&contexts),
236+
Some(DeviceClass::HIGH)
237+
);
238+
}
239+
240+
#[test]
241+
fn test_ipad99_1_returns_device_class_high() {
242+
let mut contexts = Contexts::new();
243+
contexts.add(DeviceContext {
244+
family: Annotated::new("iOS".to_string()),
245+
model: Annotated::new("iPad99,1".to_string()),
246+
..DeviceContext::default()
247+
});
248+
assert_eq!(
249+
DeviceClass::from_contexts(&contexts),
250+
Some(DeviceClass::HIGH)
251+
);
252+
}
253+
254+
#[test]
255+
fn test_garbage_device_model_returns_device_class_high() {
256+
let mut contexts = Contexts::new();
257+
contexts.add(DeviceContext {
258+
family: Annotated::new("iOS".to_string()),
259+
model: Annotated::new("garbage-device-model".to_string()),
260+
..DeviceContext::default()
261+
});
262+
assert_eq!(
263+
DeviceClass::from_contexts(&contexts),
264+
Some(DeviceClass::HIGH)
265+
);
266+
}
267+
268+
#[test]
269+
fn test_wrong_family_returns_none() {
270+
let mut contexts = Contexts::new();
271+
contexts.add(DeviceContext {
272+
family: Annotated::new("iOSS".to_string()),
273+
model: Annotated::new("iPhone17,5".to_string()),
274+
..DeviceContext::default()
275+
});
276+
assert_eq!(DeviceClass::from_contexts(&contexts), None);
204277
}
205278
}

0 commit comments

Comments
 (0)