Skip to content

ref: Normalize all non-raw stacktraces #203

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

Merged
merged 4 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions general/src/processor/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub trait Processor: Sized {

process_method!(process_event, crate::protocol::Event);
process_method!(process_exception, crate::protocol::Exception);
process_method!(process_raw_stacktrace, crate::protocol::RawStacktrace);
process_method!(process_stacktrace, crate::protocol::Stacktrace);
process_method!(process_frame, crate::protocol::Frame);
process_method!(process_request, crate::protocol::Request);
Expand Down
4 changes: 2 additions & 2 deletions general/src/protocol/exception.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::protocol::{JsonLenientString, Mechanism, Stacktrace, ThreadId};
use crate::protocol::{JsonLenientString, Mechanism, RawStacktrace, Stacktrace, ThreadId};
use crate::types::{Annotated, Object, Value};

/// A single exception.
Expand Down Expand Up @@ -26,7 +26,7 @@ pub struct Exception {

/// Optional unprocessed stack trace.
#[metastructure(skip_serialization = "empty")]
pub raw_stacktrace: Annotated<Stacktrace>,
pub raw_stacktrace: Annotated<RawStacktrace>,

/// Identifier of the thread this exception occurred in.
#[metastructure(max_chars = "enumlike")]
Expand Down
2 changes: 1 addition & 1 deletion general/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use self::fingerprint::Fingerprint;
pub use self::logentry::LogEntry;
pub use self::mechanism::{CError, MachException, Mechanism, MechanismMeta, PosixSignal};
pub use self::request::{Cookies, HeaderName, Headers, Query, Request};
pub use self::stacktrace::{Frame, FrameData, FrameVars, Stacktrace};
pub use self::stacktrace::{Frame, FrameData, FrameVars, RawStacktrace, Stacktrace};
pub use self::tags::{TagEntry, Tags};
pub use self::templateinfo::TemplateInfo;
pub use self::thread::{Thread, ThreadId};
Expand Down
41 changes: 37 additions & 4 deletions general/src/protocol/stacktrace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::{Deref, DerefMut};

use crate::protocol::{Addr, RegVal};
use crate::types::{Annotated, Array, FromValue, Object, Value};

Expand Down Expand Up @@ -171,8 +173,8 @@ impl FromValue for FrameVars {

/// Holds information about an entirey stacktrace.
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, ToValue, ProcessValue)]
#[metastructure(process_func = "process_stacktrace", value_type = "Stacktrace")]
pub struct Stacktrace {
#[metastructure(process_func = "process_raw_stacktrace", value_type = "Stacktrace")]
pub struct RawStacktrace {
#[metastructure(required = "true", nonempty = "true", skip_serialization = "empty")]
pub frames: Annotated<Array<Frame>>,

Expand All @@ -188,6 +190,37 @@ pub struct Stacktrace {
pub other: Object<Value>,
}

/// Newtype to distinguish `raw_stacktrace` attributes from the rest.
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, ToValue, ProcessValue)]
#[metastructure(process_func = "process_stacktrace")]
pub struct Stacktrace(pub RawStacktrace);

impl Deref for Stacktrace {
type Target = RawStacktrace;

fn deref(&self) -> &RawStacktrace {
&self.0
}
}

impl DerefMut for Stacktrace {
fn deref_mut(&mut self) -> &mut RawStacktrace {
&mut self.0
}
}

impl From<RawStacktrace> for Stacktrace {
fn from(stacktrace: RawStacktrace) -> Stacktrace {
Stacktrace(stacktrace)
}
}

impl From<Stacktrace> for RawStacktrace {
fn from(stacktrace: Stacktrace) -> RawStacktrace {
stacktrace.0
}
}

#[test]
fn test_frame_roundtrip() {
let json = r#"{
Expand Down Expand Up @@ -294,7 +327,7 @@ fn test_stacktrace_roundtrip() {
"lang": "rust",
"other": "value"
}"#;
let stack = Annotated::new(Stacktrace {
let stack = Annotated::new(RawStacktrace {
frames: Annotated::new(vec![Annotated::new(Frame {
function: Annotated::new("foobar".to_string()),
..Default::default()
Expand Down Expand Up @@ -331,7 +364,7 @@ fn test_stacktrace_default_values() {
]
}"#;

let stack = Annotated::new(Stacktrace {
let stack = Annotated::new(RawStacktrace {
frames: Annotated::new(vec![Annotated::new(Frame::default())]),
..Default::default()
});
Expand Down
3 changes: 2 additions & 1 deletion general/src/protocol/thread.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize, Serializer};

use crate::processor::ProcessValue;
use crate::protocol::RawStacktrace;
use crate::protocol::Stacktrace;
use crate::types::{Annotated, Empty, Error, FromValue, Object, SkipSerialization, ToValue, Value};

Expand Down Expand Up @@ -84,7 +85,7 @@ pub struct Thread {

/// Optional unprocessed stack trace.
#[metastructure(skip_serialization = "empty")]
pub raw_stacktrace: Annotated<Stacktrace>,
pub raw_stacktrace: Annotated<RawStacktrace>,

/// Indicates that this thread requested the event (usually by crashing).
pub crashed: Annotated<bool>,
Expand Down
68 changes: 38 additions & 30 deletions general/src/store/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use uuid::Uuid;
use crate::processor::{MaxChars, ProcessValue, ProcessingState, Processor};
use crate::protocol::{
AsPair, Breadcrumb, ClientSdkInfo, Context, DebugImage, Event, EventId, EventType, Exception,
Frame, IpAddr, Level, LogEntry, Request, Stacktrace, Tags, User,
Frame, IpAddr, Level, LogEntry, RawStacktrace, Request, Stacktrace, Tags, User,
};
use crate::store::{GeoIpLookup, StoreConfig};
use crate::types::{
Expand Down Expand Up @@ -325,10 +325,6 @@ impl<'a> Processor for NormalizeProcessor<'a> {
event.client_sdk.set_value(self.get_sdk_info());
}

event
.stacktrace
.apply(stacktrace::process_non_raw_stacktrace);

// Normalize connected attributes and interfaces
self.normalize_release_dist(event);
self.normalize_timestamps(event);
Expand Down Expand Up @@ -440,10 +436,6 @@ impl<'a> Processor for NormalizeProcessor<'a> {
) -> ValueAction {
exception.process_child_values(self, state);

exception
.stacktrace
.apply(stacktrace::process_non_raw_stacktrace);

lazy_static! {
static ref TYPE_VALUE_RE: Regex = Regex::new(r"^(\w+):(.*)$").unwrap();
}
Expand Down Expand Up @@ -508,9 +500,9 @@ impl<'a> Processor for NormalizeProcessor<'a> {
ValueAction::Keep
}

fn process_stacktrace(
fn process_raw_stacktrace(
&mut self,
stacktrace: &mut Stacktrace,
stacktrace: &mut RawStacktrace,
_meta: &mut Meta,
state: &ProcessingState<'_>,
) -> ValueAction {
Expand All @@ -532,6 +524,16 @@ impl<'a> Processor for NormalizeProcessor<'a> {
ValueAction::Keep
}

fn process_stacktrace(
&mut self,
stacktrace: &mut Stacktrace,
meta: &mut Meta,
_state: &ProcessingState<'_>,
) -> ValueAction {
stacktrace::process_stacktrace(&mut stacktrace.0, meta);
ValueAction::Keep
}

fn process_context(
&mut self,
context: &mut Context,
Expand Down Expand Up @@ -1094,31 +1096,37 @@ fn test_regression_backfills_abs_path_even_when_moving_stacktrace() {
value: Annotated::new("hi".to_string().into()),
..Exception::default()
})])),
stacktrace: Annotated::new(Stacktrace {
frames: Annotated::new(vec![Annotated::new(Frame {
module: Annotated::new("MyModule".to_string()),
filename: Annotated::new("MyFilename".to_string()),
function: Annotated::new("Void FooBar()".to_string()),
..Frame::default()
})]),
..Stacktrace::default()
}),
stacktrace: Annotated::new(
RawStacktrace {
frames: Annotated::new(vec![Annotated::new(Frame {
module: Annotated::new("MyModule".to_string()),
filename: Annotated::new("MyFilename".to_string()),
function: Annotated::new("Void FooBar()".to_string()),
..Frame::default()
})]),
..RawStacktrace::default()
}
.into(),
),
..Event::default()
});

let mut processor = NormalizeProcessor::default();
process_value(&mut event, &mut processor, ProcessingState::root());

let expected = Annotated::new(Stacktrace {
frames: Annotated::new(vec![Annotated::new(Frame {
module: Annotated::new("MyModule".to_string()),
filename: Annotated::new("MyFilename".to_string()),
abs_path: Annotated::new("MyFilename".to_string()),
function: Annotated::new("Void FooBar()".to_string()),
..Frame::default()
})]),
..Stacktrace::default()
});
let expected = Annotated::new(
RawStacktrace {
frames: Annotated::new(vec![Annotated::new(Frame {
module: Annotated::new("MyModule".to_string()),
filename: Annotated::new("MyFilename".to_string()),
abs_path: Annotated::new("MyFilename".to_string()),
function: Annotated::new("Void FooBar()".to_string()),
..Frame::default()
})]),
..RawStacktrace::default()
}
.into(),
);

assert_eq_dbg!(
event
Expand Down
4 changes: 2 additions & 2 deletions general/src/store/normalize/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem;

use url::Url;

use crate::protocol::{Frame, Stacktrace};
use crate::protocol::{Frame, RawStacktrace};
use crate::types::{Annotated, Array, Empty, Meta};

fn is_url(filename: &str) -> bool {
Expand All @@ -12,7 +12,7 @@ fn is_url(filename: &str) -> bool {
|| filename.starts_with("applewebdata:")
}

pub fn process_non_raw_stacktrace(stacktrace: &mut Stacktrace, _meta: &mut Meta) {
pub fn process_stacktrace(stacktrace: &mut RawStacktrace, _meta: &mut Meta) {
// This processing is only done for non raw frames (i.e. not for exception.raw_stacktrace).
if let Some(frames) = stacktrace.frames.value_mut() {
for frame in frames.iter_mut() {
Expand Down
6 changes: 3 additions & 3 deletions general/src/store/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ mod tests {

#[test]
fn test_stacktrace_missing_attribute() {
use crate::protocol::Stacktrace;
use crate::protocol::RawStacktrace;
use crate::types::ErrorKind;

let mut stack = Annotated::new(Stacktrace::default());
let mut stack = Annotated::new(RawStacktrace::default());

process_value(&mut stack, &mut SchemaProcessor, ProcessingState::root());

let expected = Annotated::new(Stacktrace {
let expected = Annotated::new(RawStacktrace {
frames: Annotated::from_error(ErrorKind::MissingAttribute, None),
..Default::default()
});
Expand Down
29 changes: 16 additions & 13 deletions general/src/store/trimming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ fn test_tags_stripping() {
fn test_databag_state_leak() {
use std::iter::repeat;

use crate::protocol::{Breadcrumb, Event, Exception, Frame, Stacktrace, Values};
use crate::protocol::{Breadcrumb, Event, Exception, Frame, RawStacktrace, Values};
use crate::types::{Map, Value};

let event = Annotated::new(Event {
Expand All @@ -478,18 +478,21 @@ fn test_databag_state_leak() {
exceptions: Annotated::new(Values::new(vec![Annotated::new(Exception {
ty: Annotated::new("TypeError".to_string()),
value: Annotated::new("important error message".to_string().into()),
stacktrace: Annotated::new(Stacktrace {
frames: Annotated::new(
repeat(Annotated::new(Frame {
function: Annotated::new("importantFunctionName".to_string()),
symbol: Annotated::new("important_symbol".to_string()),
..Default::default()
}))
.take(200)
.collect(),
),
..Default::default()
}),
stacktrace: Annotated::new(
RawStacktrace {
frames: Annotated::new(
repeat(Annotated::new(Frame {
function: Annotated::new("importantFunctionName".to_string()),
symbol: Annotated::new("important_symbol".to_string()),
..Default::default()
}))
.take(200)
.collect(),
),
..Default::default()
}
.into(),
),
..Default::default()
})])),
..Default::default()
Expand Down