-
Notifications
You must be signed in to change notification settings - Fork 93
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(on-demand): Extend support fields in the event getter #2640
Changes from 5 commits
ab19015
c3619ac
1e1bee7
c0f7180
9679a8e
a03576d
528419a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#[cfg(feature = "jsonschema")] | ||
use relay_jsonschema_derive::JsonSchema; | ||
use relay_protocol::{Annotated, Empty, FromValue, IntoValue, Object, Value}; | ||
use uuid::Uuid; | ||
|
||
use crate::processor::ProcessValue; | ||
|
||
|
@@ -161,6 +162,22 @@ pub struct DeviceContext { | |
/// Whether location support is available on the device. | ||
pub supports_location_service: Annotated<bool>, | ||
|
||
/// Width of the screen in pixels. | ||
#[metastructure(pii = "maybe")] | ||
pub screen_width_pixels: Annotated<u64>, | ||
Comment on lines
+165
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this property having pii make sense? Same for the fields below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about this, and I was like, maybe some people want to scrape those fields, since they might not want to share that information with sentry (e.g., a new device with a new resolution is being secretly tested), maybe the UUID is the only thing but also that can be delicate for some users. We can definitely omit it, idk if there is a performance overhead to this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/// Height of the screen in pixels. | ||
#[metastructure(pii = "maybe")] | ||
pub screen_height_pixels: Annotated<u64>, | ||
|
||
/// Locale of the device. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try to add more information to the doc comments, such as what is the format. I'll pick this up in my follow-up. |
||
#[metastructure(pii = "maybe")] | ||
pub locale: Annotated<String>, | ||
|
||
/// UUID of the device. | ||
#[metastructure(pii = "maybe")] | ||
pub uuid: Annotated<Uuid>, | ||
|
||
/// Additional arbitrary fields for forwards compatibility | ||
#[metastructure(additional_properties, retain = "true", pii = "maybe")] | ||
pub other: Object<Value>, | ||
|
@@ -200,6 +217,7 @@ impl super::DefaultContext for DeviceContext { | |
#[cfg(test)] | ||
mod tests { | ||
use relay_protocol::{Annotated, Object, Value}; | ||
use uuid::uuid; | ||
|
||
use super::*; | ||
use crate::protocol::Context; | ||
|
@@ -243,6 +261,10 @@ mod tests { | |
"supports_gyroscope": true, | ||
"supports_audio": true, | ||
"supports_location_service": true, | ||
"screen_width_pixels": 1920, | ||
"screen_height_pixels": 1080, | ||
"locale": "US", | ||
"uuid": "abadcade-feed-dead-beef-baddadfeeded", | ||
"other": "value", | ||
"type": "device" | ||
}"#; | ||
|
@@ -285,6 +307,10 @@ mod tests { | |
supports_gyroscope: Annotated::new(true), | ||
supports_audio: Annotated::new(true), | ||
supports_location_service: Annotated::new(true), | ||
screen_width_pixels: Annotated::new(1920), | ||
screen_height_pixels: Annotated::new(1080), | ||
locale: Annotated::new("US".to_string()), | ||
uuid: Annotated::new(uuid!("abadcade-feed-dead-beef-baddadfeeded")), | ||
other: { | ||
let mut map = Object::new(); | ||
map.insert( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -650,16 +650,59 @@ impl Getter for Event { | |
"user.geo.region" => self.user.value()?.geo.value()?.region.as_str()?.into(), | ||
"user.geo.subdivision" => self.user.value()?.geo.value()?.subdivision.as_str()?.into(), | ||
"request.method" => self.request.value()?.method.as_str()?.into(), | ||
"sdk.name" => self.client_sdk.value()?.name.as_str()?.into(), | ||
"sdk.version" => self.client_sdk.value()?.version.as_str()?.into(), | ||
|
||
// Partial implementation of contexts. | ||
"contexts.device.name" => self.context::<DeviceContext>()?.name.as_str()?.into(), | ||
"contexts.device.arch" => self.context::<DeviceContext>()?.arch.as_str()?.into(), | ||
"contexts.device.battery_level" => self | ||
.context::<DeviceContext>()? | ||
.battery_level | ||
.value()? | ||
.into(), | ||
"contexts.device.brand" => self.context::<DeviceContext>()?.brand.as_str()?.into(), | ||
"contexts.device.charging" => self.context::<DeviceContext>()?.charging.value()?.into(), | ||
"contexts.device.family" => self.context::<DeviceContext>()?.family.as_str()?.into(), | ||
"contexts.device.locale" => self.context::<DeviceContext>()?.locale.as_str()?.into(), | ||
"contexts.device.online" => self.context::<DeviceContext>()?.online.value()?.into(), | ||
"contexts.device.orientation" => self | ||
.context::<DeviceContext>()? | ||
.orientation | ||
.as_str()? | ||
.into(), | ||
"contexts.device.name" => self.context::<DeviceContext>()?.name.as_str()?.into(), | ||
"contexts.device.screen_density" => self | ||
.context::<DeviceContext>()? | ||
.screen_density | ||
.value()? | ||
.into(), | ||
"contexts.device.screen_dpi" => { | ||
self.context::<DeviceContext>()?.screen_dpi.value()?.into() | ||
} | ||
"contexts.device.screen_width_pixels" => self | ||
.context::<DeviceContext>()? | ||
.screen_width_pixels | ||
.value()? | ||
.into(), | ||
"contexts.device.screen_height_pixels" => self | ||
.context::<DeviceContext>()? | ||
.screen_height_pixels | ||
.value()? | ||
.into(), | ||
"contexts.device.simulator" => { | ||
self.context::<DeviceContext>()?.simulator.value()?.into() | ||
} | ||
"contexts.os.build" => self.context::<OsContext>()?.build.as_str()?.into(), | ||
"contexts.os.kernel_version" => { | ||
self.context::<OsContext>()?.kernel_version.as_str()?.into() | ||
} | ||
"contexts.os.name" => self.context::<OsContext>()?.name.as_str()?.into(), | ||
"contexts.os.version" => self.context::<OsContext>()?.version.as_str()?.into(), | ||
"contexts.browser.name" => self.context::<BrowserContext>()?.name.as_str()?.into(), | ||
"contexts.browser.version" => { | ||
self.context::<BrowserContext>()?.version.as_str()?.into() | ||
} | ||
"contexts.device.uuid" => self.context::<DeviceContext>()?.uuid.value()?.into(), | ||
"contexts.trace.status" => self | ||
.context::<TraceContext>()? | ||
.status | ||
|
@@ -717,6 +760,7 @@ mod tests { | |
use chrono::{TimeZone, Utc}; | ||
use relay_protocol::{ErrorKind, Map, Meta}; | ||
use similar_asserts::assert_eq; | ||
use uuid::uuid; | ||
|
||
use super::*; | ||
use crate::protocol::{Headers, IpAddr, JsonLenientString, PairList, TagEntry}; | ||
|
@@ -998,6 +1042,11 @@ mod tests { | |
segment: Annotated::new("user-seg".into()), | ||
..Default::default() | ||
}), | ||
client_sdk: Annotated::new(ClientSdkInfo { | ||
name: Annotated::new("sentry-javascript".into()), | ||
version: Annotated::new("1.87.0".into()), | ||
..Default::default() | ||
}), | ||
exceptions: Annotated::new(Values { | ||
values: Annotated::new(vec![Annotated::new(Exception { | ||
value: Annotated::new(JsonLenientString::from( | ||
|
@@ -1028,6 +1077,12 @@ mod tests { | |
name: Annotated::new("iphone".to_string()), | ||
family: Annotated::new("iphone-fam".to_string()), | ||
model: Annotated::new("iphone7,3".to_string()), | ||
screen_dpi: Annotated::new(560), | ||
screen_width_pixels: Annotated::new(1920), | ||
screen_height_pixels: Annotated::new(1080), | ||
locale: Annotated::new("US".into()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A correct value for this field would be |
||
uuid: Annotated::new(uuid!("abadcade-feed-dead-beef-baddadfeeded")), | ||
charging: Annotated::new(true), | ||
..DeviceContext::default() | ||
}); | ||
contexts.add(OsContext { | ||
|
@@ -1079,6 +1134,42 @@ mod tests { | |
event.get_value("event.tags.custom") | ||
); | ||
assert_eq!(None, event.get_value("event.tags.doesntexist")); | ||
assert_eq!( | ||
Some(Val::String("sentry-javascript")), | ||
event.get_value("event.sdk.name") | ||
); | ||
assert_eq!( | ||
Some(Val::String("1.87.0")), | ||
event.get_value("event.sdk.version") | ||
); | ||
assert_eq!( | ||
Some(Val::String("17.4.0")), | ||
event.get_value("event.contexts.os.kernel_version") | ||
); | ||
assert_eq!( | ||
Some(Val::I64(560)), | ||
event.get_value("event.contexts.device.screen_dpi") | ||
); | ||
assert_eq!( | ||
Some(Val::Bool(true)), | ||
event.get_value("event.contexts.device.charging") | ||
); | ||
assert_eq!( | ||
Some(Val::U64(1920)), | ||
event.get_value("event.contexts.device.screen_width_pixels") | ||
); | ||
assert_eq!( | ||
Some(Val::U64(1080)), | ||
event.get_value("event.contexts.device.screen_height_pixels") | ||
); | ||
assert_eq!( | ||
Some(Val::String("US")), | ||
event.get_value("event.contexts.device.locale") | ||
); | ||
assert_eq!( | ||
Some(Val::Uuid(uuid!("abadcade-feed-dead-beef-baddadfeeded"))), | ||
event.get_value("event.contexts.device.uuid") | ||
); | ||
} | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR extends the event schema. Could we move this to the features section, and also update the py/changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure