From ab19015af963048a332d843b26d47e78d7e658c8 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 20 Oct 2023 10:50:51 +0200 Subject: [PATCH 1/6] feat(on-demand): Extend support fields in the event getter --- relay-event-schema/src/protocol/event.rs | 46 +++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/relay-event-schema/src/protocol/event.rs b/relay-event-schema/src/protocol/event.rs index af08d0b7d3..73c0f9a91b 100644 --- a/relay-event-schema/src/protocol/event.rs +++ b/relay-event-schema/src/protocol/event.rs @@ -650,10 +650,41 @@ 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::()?.name.as_str()?.into(), + "contexts.device.arch" => self.context::()?.arch.as_str()?.into(), + "contexts.device.battery_level" => self + .context::()? + .battery_level + .value()? + .into(), + "contexts.device.brand" => self.context::()?.brand.as_str()?.into(), + "contexts.device.charging" => self.context::()?.charging.value()?.into(), "contexts.device.family" => self.context::()?.family.as_str()?.into(), + "contexts.device.online" => self.context::()?.online.value()?.into(), + "contexts.device.orientation" => self + .context::()? + .orientation + .as_str()? + .into(), + "contexts.device.name" => self.context::()?.name.as_str()?.into(), + "contexts.device.screen_density" => self + .context::()? + .screen_density + .value()? + .into(), + "contexts.device.screen_dpi" => { + self.context::()?.screen_dpi.value()?.into() + } + "contexts.device.simulator" => { + self.context::()?.simulator.value()?.into() + } + "contexts.os.build" => self.context::()?.build.as_str()?.into(), + "contexts.os.kernel_version" => { + self.context::()?.kernel_version.as_str()?.into() + } "contexts.os.name" => self.context::()?.name.as_str()?.into(), "contexts.os.version" => self.context::()?.version.as_str()?.into(), "contexts.browser.name" => self.context::()?.name.as_str()?.into(), @@ -998,6 +1029,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( @@ -1079,6 +1115,14 @@ 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") + ); } #[test] From c3619ac4e013da6e9fb79278e293cafc9da5aa44 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 20 Oct 2023 10:58:09 +0200 Subject: [PATCH 2/6] Add tests --- relay-event-schema/src/protocol/event.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/relay-event-schema/src/protocol/event.rs b/relay-event-schema/src/protocol/event.rs index 73c0f9a91b..2e46df393e 100644 --- a/relay-event-schema/src/protocol/event.rs +++ b/relay-event-schema/src/protocol/event.rs @@ -1064,6 +1064,8 @@ 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), + charging: Annotated::new(true), ..DeviceContext::default() }); contexts.add(OsContext { @@ -1123,6 +1125,18 @@ mod tests { 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") + ); } #[test] From 1e1bee7b86035283b16ff2ff5eb7093f8d7bece6 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 20 Oct 2023 14:14:29 +0200 Subject: [PATCH 3/6] Implement --- .../src/protocol/contexts/device.rs | 26 +++++++++++++++ relay-event-schema/src/protocol/event.rs | 33 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/relay-event-schema/src/protocol/contexts/device.rs b/relay-event-schema/src/protocol/contexts/device.rs index 36a6cd7321..e928de80b2 100644 --- a/relay-event-schema/src/protocol/contexts/device.rs +++ b/relay-event-schema/src/protocol/contexts/device.rs @@ -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, + /// Width of the screen in pixels. + #[metastructure(pii = "maybe")] + pub screen_width_pixels: Annotated, + + /// Height of the screen in pixels. + #[metastructure(pii = "maybe")] + pub screen_height_pixels: Annotated, + + /// Locale of the device. + #[metastructure(pii = "maybe")] + pub locale: Annotated, + + /// UUID of the device. + #[metastructure(pii = "maybe")] + pub uuid: Annotated, + /// Additional arbitrary fields for forwards compatibility #[metastructure(additional_properties, retain = "true", pii = "maybe")] pub other: Object, @@ -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( diff --git a/relay-event-schema/src/protocol/event.rs b/relay-event-schema/src/protocol/event.rs index 2e46df393e..4240a6d1a0 100644 --- a/relay-event-schema/src/protocol/event.rs +++ b/relay-event-schema/src/protocol/event.rs @@ -663,6 +663,7 @@ impl Getter for Event { "contexts.device.brand" => self.context::()?.brand.as_str()?.into(), "contexts.device.charging" => self.context::()?.charging.value()?.into(), "contexts.device.family" => self.context::()?.family.as_str()?.into(), + "contexts.device.locale" => self.context::()?.locale.as_str()?.into(), "contexts.device.online" => self.context::()?.online.value()?.into(), "contexts.device.orientation" => self .context::()? @@ -678,6 +679,16 @@ impl Getter for Event { "contexts.device.screen_dpi" => { self.context::()?.screen_dpi.value()?.into() } + "contexts.device.screen_width_pixels" => self + .context::()? + .screen_width_pixels + .value()? + .into(), + "contexts.device.screen_height_pixels" => self + .context::()? + .screen_height_pixels + .value()? + .into(), "contexts.device.simulator" => { self.context::()?.simulator.value()?.into() } @@ -691,6 +702,7 @@ impl Getter for Event { "contexts.browser.version" => { self.context::()?.version.as_str()?.into() } + "contexts.device.uuid" => self.context::()?.uuid.value()?.into(), "contexts.trace.status" => self .context::()? .status @@ -748,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}; @@ -1065,6 +1078,10 @@ mod tests { 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()), + uuid: Annotated::new(uuid!("abadcade-feed-dead-beef-baddadfeeded")), charging: Annotated::new(true), ..DeviceContext::default() }); @@ -1137,6 +1154,22 @@ mod tests { 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] From c0f71803697981a54a945ebf9a733f63dce0de77 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 20 Oct 2023 14:27:58 +0200 Subject: [PATCH 4/6] Update fixtures --- ...test_fixtures__android__pii_stripping.snap | 4 +- .../test_fixtures__event_schema.snap | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/relay-server/tests/snapshots/test_fixtures__android__pii_stripping.snap b/relay-server/tests/snapshots/test_fixtures__android__pii_stripping.snap index b680c0f186..7bf13a4e3f 100644 --- a/relay-server/tests/snapshots/test_fixtures__android__pii_stripping.snap +++ b/relay-server/tests/snapshots/test_fixtures__android__pii_stripping.snap @@ -45,11 +45,11 @@ expression: SerializableAnnotated(&event) "external_free_storage": 534702080, "boot_time": null, "timezone": null, + "screen_width_pixels": null, + "screen_height_pixels": null, "archs": [ "x86" ], - "screen_height_pixels": null, - "screen_width_pixels": null, "type": "device" }, "os": { diff --git a/relay-server/tests/snapshots/test_fixtures__event_schema.snap b/relay-server/tests/snapshots/test_fixtures__event_schema.snap index a20c258a92..b1d3450f78 100644 --- a/relay-server/tests/snapshots/test_fixtures__event_schema.snap +++ b/relay-server/tests/snapshots/test_fixtures__event_schema.snap @@ -1209,6 +1209,14 @@ expression: "relay_event_schema::protocol::event_json_schema()" "format": "uint64", "minimum": 0.0 }, + "locale": { + "description": " Locale of the device.", + "default": null, + "type": [ + "string", + "null" + ] + }, "low_memory": { "description": " Whether the device was low on memory.", "default": null, @@ -1314,6 +1322,16 @@ expression: "relay_event_schema::protocol::event_json_schema()" "format": "uint64", "minimum": 0.0 }, + "screen_height_pixels": { + "description": " Height of the screen in pixels.", + "default": null, + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, "screen_resolution": { "description": " Device screen resolution.\n\n (e.g.: 800x600, 3040x1444)", "default": null, @@ -1322,6 +1340,16 @@ expression: "relay_event_schema::protocol::event_json_schema()" "null" ] }, + "screen_width_pixels": { + "description": " Width of the screen in pixels.", + "default": null, + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, "simulator": { "description": " Simulator/prod indicator.", "default": null, @@ -1397,6 +1425,15 @@ expression: "relay_event_schema::protocol::event_json_schema()" ], "format": "uint64", "minimum": 0.0 + }, + "uuid": { + "description": " UUID of the device.", + "default": null, + "type": [ + "string", + "null" + ], + "format": "uuid" } }, "additionalProperties": false From 9679a8edeb0984702cfc8e05a63c25b3fbe23963 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Fri, 20 Oct 2023 14:35:22 +0200 Subject: [PATCH 5/6] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf97c2c6c..18d61acb65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Restrict resource spans to script and css only. ([#2623](https://github.com/getsentry/relay/pull/2623)) - Postpone metrics aggregation until we received the project state. ([#2588](https://github.com/getsentry/relay/pull/2588)) - Scrub random strings in resource span descriptions. ([#2614](https://github.com/getsentry/relay/pull/2614)) +- Extend the number of supported fields for the `Event` `Getter`. ([#2640](https://github.com/getsentry/relay/pull/2640)) ## 23.10.0 From a03576d17ac012d38e842489cdf87c8706af52c6 Mon Sep 17 00:00:00 2001 From: Riccardo Busetti Date: Mon, 23 Oct 2023 08:39:27 +0200 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 2 +- py/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18d61acb65..c14b7d809e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ **Features**: - Update Docker Debian image from 10 to 12. ([#2622](https://github.com/getsentry/relay/pull/2622)) +- Extend the number of supported fields for the `Event` `Getter`. ([#2640](https://github.com/getsentry/relay/pull/2640)) **Internal**: @@ -12,7 +13,6 @@ - Restrict resource spans to script and css only. ([#2623](https://github.com/getsentry/relay/pull/2623)) - Postpone metrics aggregation until we received the project state. ([#2588](https://github.com/getsentry/relay/pull/2588)) - Scrub random strings in resource span descriptions. ([#2614](https://github.com/getsentry/relay/pull/2614)) -- Extend the number of supported fields for the `Event` `Getter`. ([#2640](https://github.com/getsentry/relay/pull/2640)) ## 23.10.0 diff --git a/py/CHANGELOG.md b/py/CHANGELOG.md index dfde8f20d4..976105929d 100644 --- a/py/CHANGELOG.md +++ b/py/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `scraping_attempts` field to the event schema. ([#2575](https://github.com/getsentry/relay/pull/2575)) - Drop events starting or ending before January 1, 1970 UTC. ([#2613](https://github.com/getsentry/relay/pull/2613)) +- Extend the number of supported fields for the `Event` `Getter`. ([#2640](https://github.com/getsentry/relay/pull/2640)) ## 0.8.31