Skip to content

Commit

Permalink
feat(protocol): Add Linux distributions to os context (#3443)
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus authored Apr 18, 2024
1 parent c5cde46 commit a3f169e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## Unreleased

**Features:**
**Features**:

- Add inbound filters for Annotated<Replay> types. ([#3420](https://github.com/getsentry/relay/pull/3420))
- Add Linux distributions to os context. ([#3443](https://github.com/getsentry/relay/pull/3443))

**Internal:**

Expand Down
2 changes: 2 additions & 0 deletions relay-event-normalization/src/normalize/user_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ OsContext {
build: ~,
kernel_version: ~,
rooted: ~,
distribution: ~,
raw_description: ~,
other: {},
}
Expand Down Expand Up @@ -1028,6 +1029,7 @@ OsContext {
build: ~,
kernel_version: ~,
rooted: ~,
distribution: ~,
raw_description: ~,
other: {},
}
Expand Down
61 changes: 61 additions & 0 deletions relay-event-schema/src/protocol/contexts/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub struct OsContext {
/// Indicator if the OS is rooted (mobile mostly).
pub rooted: Annotated<bool>,

/// Meta-data for the Linux Distribution.
#[metastructure(skip_serialization = "empty")]
pub distribution: Annotated<LinuxDistribution>,

/// Unprocessed operating system info.
///
/// An unprocessed description string obtained by the operating system. For some well-known
Expand All @@ -44,6 +48,29 @@ pub struct OsContext {
pub other: Object<Value>,
}

/// Metadata for the Linux Distribution.
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct LinuxDistribution {
/// An index-able name that is stable for each distribution.
pub name: Annotated<String>,
/// The version of the distribution (missing in distributions with solely rolling release).
#[metastructure(skip_serialization = "empty")]
pub version: Annotated<String>,
/// A full rendering of name + version + release name (not available in all distributions).
#[metastructure(skip_serialization = "empty")]
pub pretty_name: Annotated<String>,

/// Additional arbitrary fields for forwards compatibility.
#[metastructure(
additional_properties,
retain = "true",
pii = "maybe",
skip_serialization = "empty"
)]
pub other: Object<Value>,
}

impl super::DefaultContext for OsContext {
fn default_key() -> &'static str {
"os"
Expand Down Expand Up @@ -99,6 +126,7 @@ mod tests {
kernel_version: Annotated::new("17.4.0".to_string()),
rooted: Annotated::new(true),
raw_description: Annotated::new("iOS 11.4.2 FEEDFACE (17.4.0)".to_string()),
distribution: Annotated::empty(),
other: {
let mut map = Object::new();
map.insert(
Expand All @@ -112,4 +140,37 @@ mod tests {
assert_eq!(context, Annotated::from_json(json).unwrap());
assert_eq!(json, context.to_json_pretty().unwrap());
}

#[test]
fn test_os_context_linux_roundtrip() {
let json = r#"{
"name": "Linux",
"version": "5.15.133",
"build": "1-microsoft-standard-WSL2",
"distribution": {
"name": "ubuntu",
"version": "22.04",
"pretty_name": "Ubuntu 22.04.4 LTS"
},
"type": "os"
}"#;
let context = Annotated::new(Context::Os(Box::new(OsContext {
name: Annotated::new("Linux".to_string()),
version: Annotated::new("5.15.133".to_string()),
build: Annotated::new(LenientString("1-microsoft-standard-WSL2".to_string())),
kernel_version: Annotated::empty(),
rooted: Annotated::empty(),
raw_description: Annotated::empty(),
distribution: Annotated::new(LinuxDistribution {
name: Annotated::new("ubuntu".to_string()),
version: Annotated::new("22.04".to_string()),
pretty_name: Annotated::new("Ubuntu 22.04.4 LTS".to_string()),
other: Object::default(),
}),
other: Object::default(),
})));

assert_eq!(context, Annotated::from_json(json).unwrap());
assert_eq!(json, context.to_json_pretty().unwrap());
}
}
47 changes: 47 additions & 0 deletions relay-server/tests/snapshots/test_fixtures__event_schema.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,41 @@ expression: "relay_event_schema::protocol::event_json_schema()"
"fatal"
]
},
"LinuxDistribution": {
"description": " Metadata for the Linux Distribution.",
"anyOf": [
{
"type": "object",
"properties": {
"name": {
"description": " An index-able name that is stable for each distribution.",
"default": null,
"type": [
"string",
"null"
]
},
"pretty_name": {
"description": " A full rendering of name + version + release name (not available in all distributions).",
"default": null,
"type": [
"string",
"null"
]
},
"version": {
"description": " The version of the distribution (missing in distributions with solely rolling release).",
"default": null,
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
}
]
},
"LockReason": {
"description": " Represents an instance of a held lock (java monitor object) in a thread.",
"anyOf": [
Expand Down Expand Up @@ -2756,6 +2791,18 @@ expression: "relay_event_schema::protocol::event_json_schema()"
"null"
]
},
"distribution": {
"description": " Meta-data for the Linux Distribution.",
"default": null,
"anyOf": [
{
"$ref": "#/definitions/LinuxDistribution"
},
{
"type": "null"
}
]
},
"kernel_version": {
"description": " Current kernel version.\n\n This is typically the entire output of the `uname` syscall.",
"default": null,
Expand Down

0 comments on commit a3f169e

Please sign in to comment.