Skip to content

Commit

Permalink
feat(general): Implement advanced context normalization (#140)
Browse files Browse the repository at this point in the history
* feat(contexts): Add runtime build attribute

* ref(general): Remove field trimming from contexts

* feat(general): Implement os and runtime context normalization

* feat(general): Normalize arbitrary context types to default
  • Loading branch information
jan-auer committed Jan 16, 2019
1 parent c8d4043 commit 1ade63c
Show file tree
Hide file tree
Showing 3 changed files with 338 additions and 18 deletions.
25 changes: 8 additions & 17 deletions general/src/protocol/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,21 @@ pub struct DeviceContext {
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, ToValue, ProcessValue)]
pub struct OsContext {
/// Name of the operating system.
#[metastructure(max_chars = "summary")]
pub name: Annotated<String>,

/// Version of the operating system.
#[metastructure(max_chars = "summary")]
pub version: Annotated<String>,

/// Internal build number of the operating system.
#[metastructure(max_chars = "summary")]
pub build: Annotated<String>,
pub build: Annotated<LenientString>,

/// Current kernel version.
#[metastructure(max_chars = "summary")]
pub kernel_version: Annotated<String>,

/// Indicator if the OS is rooted (mobile mostly).
pub rooted: Annotated<bool>,

/// Unprocessed operating system info.
#[metastructure(max_chars = "summary")]
pub raw_description: Annotated<String>,

/// Additional arbitrary fields for forwards compatibility.
Expand All @@ -97,15 +92,15 @@ pub struct OsContext {
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, ToValue, ProcessValue)]
pub struct RuntimeContext {
/// Runtime name.
#[metastructure(max_chars = "summary")]
pub name: Annotated<String>,

/// Runtime version.
#[metastructure(max_chars = "summary")]
/// Runtime version string.
pub version: Annotated<String>,

/// Application build string, if it is separate from the version.
pub build: Annotated<LenientString>,

/// Unprocessed runtime info.
#[metastructure(max_chars = "summary")]
pub raw_description: Annotated<String>,

/// Additional arbitrary fields for forwards compatibility.
Expand All @@ -120,12 +115,9 @@ pub struct AppContext {
pub app_start_time: Annotated<DateTime<Utc>>,

/// Device app hash (app specific device ID)
#[metastructure(pii = "true")]
#[metastructure(max_chars = "summary")]
pub device_app_hash: Annotated<String>,

/// Build identicator.
#[metastructure(max_chars = "summary")]
pub build_type: Annotated<String>,

/// App identifier (dotted bundle id).
Expand All @@ -138,7 +130,6 @@ pub struct AppContext {
pub app_version: Annotated<String>,

/// Internal build ID as it appears on the platform.
#[metastructure(max_chars = "summary")]
pub app_build: Annotated<LenientString>,

/// Additional arbitrary fields for forwards compatibility.
Expand All @@ -150,11 +141,9 @@ pub struct AppContext {
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, ToValue, ProcessValue)]
pub struct BrowserContext {
/// Runtime name.
#[metastructure(max_chars = "summary")]
pub name: Annotated<String>,

/// Runtime version.
#[metastructure(max_chars = "summary")]
pub version: Annotated<String>,

/// Additional arbitrary fields for forwards compatibility.
Expand Down Expand Up @@ -288,7 +277,7 @@ fn test_os_context_roundtrip() {
let context = Annotated::new(Context::Os(Box::new(OsContext {
name: Annotated::new("iOS".to_string()),
version: Annotated::new("11.4.2".to_string()),
build: Annotated::new("FEEDFACE".to_string()),
build: Annotated::new(LenientString("FEEDFACE".to_string())),
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()),
Expand All @@ -311,13 +300,15 @@ fn test_runtime_context_roundtrip() {
let json = r#"{
"name": "rustc",
"version": "1.27.0",
"build": "stable",
"raw_description": "rustc 1.27.0 stable",
"other": "value",
"type": "runtime"
}"#;
let context = Annotated::new(Context::Runtime(Box::new(RuntimeContext {
name: Annotated::new("rustc".to_string()),
version: Annotated::new("1.27.0".to_string()),
build: Annotated::new(LenientString("stable".to_string())),
raw_description: Annotated::new("rustc 1.27.0 stable".to_string()),
other: {
let mut map = Object::new();
Expand Down
13 changes: 12 additions & 1 deletion general/src/store/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ use uuid::Uuid;

use crate::processor::{MaxChars, ProcessValue, ProcessingState, Processor};
use crate::protocol::{
Breadcrumb, ClientSdkInfo, Event, EventId, EventType, Exception, Frame, IpAddr, Level, Request,
Breadcrumb, ClientSdkInfo, Context, Event, EventId, EventType, Exception, Frame, IpAddr, Level, Request,
Stacktrace, Tags, User,
};
use crate::store::{GeoIpLookup, StoreConfig};
use crate::types::{Annotated, Empty, Error, ErrorKind, Meta, Object, ValueAction};

mod contexts;
mod mechanism;
mod request;
mod stacktrace;
Expand Down Expand Up @@ -455,6 +456,16 @@ impl<'a> Processor for NormalizeProcessor<'a> {

ValueAction::Keep
}

fn process_context(
&mut self,
context: &mut Context,
_meta: &mut Meta,
_state: &ProcessingState<'_>,
) -> ValueAction {
contexts::normalize_context(context);
ValueAction::Keep
}
}

#[cfg(test)]
Expand Down

0 comments on commit 1ade63c

Please sign in to comment.