Skip to content

Commit

Permalink
feat(schema): Add missing fields to DeviceContext (#1383)
Browse files Browse the repository at this point in the history
This PR syncs the DeviceContext with https://develop.sentry.dev/sdk/event-payloads/contexts/#device-context

Adds `processor_count`, `cpu_description`, `processor_frequency`, `device_type`, `battery_status`, `device_unique_identifier`, `supports_vibration`, `supports_accelerometer`, `supports_gyroscope`, `supports_audio`, and `supports_location_service`.
  • Loading branch information
AbhiPrasad authored Aug 8, 2022
1 parent 0d74eb9 commit 39f69a7
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Re-encode the Typescript payload to normalize. ([#1372](https://github.com/getsentry/relay/pull/1372))
- Partially normalize events before extracting metrics. ([#1366](https://github.com/getsentry/relay/pull/1366))
- Spawn more threads for CPU intensive work. ([#1378](https://github.com/getsentry/relay/pull/1378))
- Add missing fields to DeviceContext ([#1383](https://github.com/getsentry/relay/pull/1383))

## 22.7.0

Expand Down
72 changes: 71 additions & 1 deletion relay-general/src/protocol/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,55 @@ pub struct DeviceContext {
#[metastructure(pii = "maybe")]
pub timezone: Annotated<String>,

/// Additional arbitrary fields for forwards compatibility.
/// Number of "logical processors".
///
/// For example, 8.
pub processor_count: Annotated<u64>,

/// CPU description.
///
/// For example, Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz.
#[metastructure(pii = "maybe")]
pub cpu_description: Annotated<String>,

/// Processor frequency in MHz.
///
/// Note that the actual CPU frequency might vary depending on current load and
/// power conditions, especially on low-powered devices like phones and laptops.
pub processor_frequency: Annotated<u64>,

/// Kind of device the application is running on.
///
/// For example, `Unknown`, `Handheld`, `Console`, `Desktop`.
#[metastructure(pii = "maybe")]
pub device_type: Annotated<String>,

/// Status of the device's battery.
///
/// For example, `Unknown`, `Charging`, `Discharging`, `NotCharging`, `Full`.
#[metastructure(pii = "maybe")]
pub battery_status: Annotated<String>,

/// Unique device identifier.
#[metastructure(pii = "true")]
pub device_unique_identifier: Annotated<String>,

/// Whether vibration is available on the device.
pub supports_vibration: Annotated<bool>,

/// Whether the accelerometer is available on the device.
pub supports_accelerometer: Annotated<bool>,

/// Whether the gyroscope is available on the device.
pub supports_gyroscope: Annotated<bool>,

/// Whether audio is available on the device.
pub supports_audio: Annotated<bool>,

/// Whether location support is available on the device.
pub supports_location_service: Annotated<bool>,

/// Additional arbitrary fields for forwards compatibility
#[metastructure(additional_properties, retain = "true", pii = "maybe")]
pub other: Object<Value>,
}
Expand Down Expand Up @@ -775,6 +823,17 @@ fn test_device_context_roundtrip() {
"external_free_storage": 2097152,
"boot_time": "2018-02-08T12:52:12Z",
"timezone": "Europe/Vienna",
"processor_count": 8,
"cpu_description": "Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz",
"processor_frequency": 2400,
"device_type": "Handheld",
"battery_status": "Charging",
"device_unique_identifier": "1234567",
"supports_vibration": true,
"supports_accelerometer": true,
"supports_gyroscope": true,
"supports_audio": true,
"supports_location_service": true,
"other": "value",
"type": "device"
}"#;
Expand Down Expand Up @@ -804,6 +863,17 @@ fn test_device_context_roundtrip() {
external_free_storage: Annotated::new(2_097_152),
boot_time: Annotated::new("2018-02-08T12:52:12Z".to_string()),
timezone: Annotated::new("Europe/Vienna".to_string()),
processor_count: Annotated::new(8),
cpu_description: Annotated::new("Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz".to_string()),
processor_frequency: Annotated::new(2400),
device_type: Annotated::new("Handheld".to_string()),
battery_status: Annotated::new("Charging".to_string()),
device_unique_identifier: Annotated::new("1234567".to_string()),
supports_vibration: Annotated::new(true),
supports_accelerometer: Annotated::new(true),
supports_gyroscope: Annotated::new(true),
supports_audio: Annotated::new(true),
supports_location_service: Annotated::new(true),
other: {
let mut map = Object::new();
map.insert(
Expand Down
92 changes: 92 additions & 0 deletions relay-general/tests/snapshots/test_fixtures__event_schema.snap
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,14 @@ expression: event_json_schema()
],
"format": "double"
},
"battery_status": {
"description": " Status of the device's battery.\n\n For example, `Unknown`, `Charging`, `Discharging`, `NotCharging`, `Full`.",
"default": null,
"type": [
"string",
"null"
]
},
"boot_time": {
"description": " Indicator when the device was booted.",
"default": null,
Expand All @@ -1006,6 +1014,30 @@ expression: event_json_schema()
"null"
]
},
"cpu_description": {
"description": " CPU description.\n\n For example, Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz.",
"default": null,
"type": [
"string",
"null"
]
},
"device_type": {
"description": " Kind of device the application is running on.\n\n For example, `Unknown`, `Handheld`, `Console`, `Desktop`.",
"default": null,
"type": [
"string",
"null"
]
},
"device_unique_identifier": {
"description": " Unique device identifier.",
"default": null,
"type": [
"string",
"null"
]
},
"external_free_storage": {
"description": " Free size of the attached external storage in bytes (eg: android SDK card).",
"default": null,
Expand Down Expand Up @@ -1120,6 +1152,26 @@ expression: event_json_schema()
"null"
]
},
"processor_count": {
"description": " Number of \"logical processors\".\n\n For example, 8.",
"default": null,
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"processor_frequency": {
"description": " Processor frequency in MHz.\n\n Note that the actual CPU frequency might vary depending on current load and\n power conditions, especially on low-powered devices like phones and laptops.",
"default": null,
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"screen_density": {
"description": " Device screen density.",
"default": null,
Expand Down Expand Up @@ -1165,6 +1217,46 @@ expression: event_json_schema()
"format": "uint64",
"minimum": 0.0
},
"supports_accelerometer": {
"description": " Whether the accelerometer is available on the device.",
"default": null,
"type": [
"boolean",
"null"
]
},
"supports_audio": {
"description": " Whether audio is available on the device.",
"default": null,
"type": [
"boolean",
"null"
]
},
"supports_gyroscope": {
"description": " Whether the gyroscope is available on the device.",
"default": null,
"type": [
"boolean",
"null"
]
},
"supports_location_service": {
"description": " Whether location support is available on the device.",
"default": null,
"type": [
"boolean",
"null"
]
},
"supports_vibration": {
"description": " Whether vibration is available on the device.",
"default": null,
"type": [
"boolean",
"null"
]
},
"timezone": {
"description": " Timezone of the device.",
"default": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ contexts:
memory_size: ~
boot_time: ~
timezone: ~
battery_status: NotCharging
processor_count: 16
cpu_description: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
device_type: Desktop
processor_count: 16
battery_status: NotCharging
supports_vibration: false
type: device
gpu:
Expand Down Expand Up @@ -288,3 +288,4 @@ _meta:
- 7
- 13
len: 69

Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ contexts:
memory_size: ~
boot_time: ~
timezone: ~
battery_status: NotCharging
processor_count: 16
cpu_description: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
device_type: Desktop
processor_count: 16
battery_status: NotCharging
supports_vibration: false
type: device
gpu:
Expand Down Expand Up @@ -288,3 +288,4 @@ _meta:
- 7
- 13
len: 69

Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ contexts:
memory_size: ~
boot_time: ~
timezone: ~
battery_status: NotCharging
processor_count: 16
cpu_description: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
device_type: Desktop
processor_count: 16
battery_status: NotCharging
supports_vibration: false
type: device
gpu:
Expand Down Expand Up @@ -288,3 +288,4 @@ _meta:
- 7
- 13
len: 69

Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ contexts:
memory_size: ~
boot_time: ~
timezone: ~
battery_status: NotCharging
processor_count: 16
cpu_description: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
device_type: Desktop
processor_count: 16
battery_status: NotCharging
supports_vibration: false
type: device
gpu:
Expand Down Expand Up @@ -288,3 +288,4 @@ _meta:
- 7
- 13
len: 69

Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ contexts:
memory_size: ~
boot_time: ~
timezone: ~
battery_status: Full
processor_count: 12
cpu_description: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
device_type: Desktop
processor_count: 12
battery_status: Full
supports_vibration: false
timezone_display_name: "(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius"
type: device
Expand Down Expand Up @@ -256,3 +256,4 @@ _meta:
rem:
- - "@anything:remove"
- x

0 comments on commit 39f69a7

Please sign in to comment.