Skip to content

Commit

Permalink
chore: skip when exception list is missing (#25784)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Oct 24, 2024
1 parent 75e28ba commit 834aed4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
9 changes: 7 additions & 2 deletions rust/cymbal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,17 @@ async fn main() -> Result<(), Error> {
}
};

if properties.exception_list.is_empty() {
let Some(exception_list) = &properties.exception_list else {
// Known issue that $exception_list didn't exist on old clients
continue;
};

if exception_list.is_empty() {
metrics::counter!(ERRORS, "cause" => "no_exception_list").increment(1);
continue;
}

let Some(trace) = properties.exception_list[0].stacktrace.as_ref() else {
let Some(trace) = exception_list[0].stacktrace.as_ref() else {
metrics::counter!(ERRORS, "cause" => "no_stack_trace").increment(1);
continue;
};
Expand Down
2 changes: 1 addition & 1 deletion rust/cymbal/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod test {

let exception: ClickHouseEvent = serde_json::from_str(EXAMPLE_EXCEPTION).unwrap();
let props: ErrProps = serde_json::from_str(&exception.properties.unwrap()).unwrap();
let mut test_stack: Vec<RawFrame> = props.exception_list[0]
let mut test_stack: Vec<RawFrame> = props.exception_list.unwrap()[0]
.stacktrace
.as_ref()
.unwrap()
Expand Down
30 changes: 8 additions & 22 deletions rust/cymbal/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Exception {
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct ErrProps {
#[serde(rename = "$exception_list")]
pub exception_list: Vec<Exception>, // Required from exception producers - we will not process events without this
pub exception_list: Option<Vec<Exception>>, // Required from exception producers - we will not process events without this. Optional to support older clients, should eventually be removed
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "$exception_type")]
pub exception_type: Option<String>, // legacy, overridden by exception_list
Expand All @@ -69,45 +69,31 @@ mod test {

use super::ErrProps;

#[test]
fn it_requires_exception_list() {
let raw: &'static str = include_str!("../../tests/static/raw_ch_exception.json");

let raw: ClickHouseEvent = serde_json::from_str(raw).unwrap();

// errors out because of missing exception_list property, which is required
let props: Result<ErrProps, Error> = serde_json::from_str(&raw.properties.unwrap());
assert!(props.is_err());
assert_eq!(
props.unwrap_err().to_string(),
"missing field `$exception_list` at line 275 column 5"
);
}

#[test]
fn it_deserialises_error_props() {
let raw: &'static str = include_str!("../../tests/static/raw_ch_exception_list.json");

let raw: ClickHouseEvent = serde_json::from_str(raw).unwrap();

let props: ErrProps = serde_json::from_str(&raw.properties.unwrap()).unwrap();
let exception_list = &props.exception_list.unwrap();

assert_eq!(props.exception_list.len(), 1);
assert_eq!(exception_list.len(), 1);
assert_eq!(
props.exception_list[0].exception_type,
exception_list[0].exception_type,
"UnhandledRejection".to_string()
);
assert_eq!(
props.exception_list[0].exception_message,
exception_list[0].exception_message,
"Unexpected usage".to_string()
);
let mechanism = props.exception_list[0].mechanism.as_ref().unwrap();
let mechanism = exception_list[0].mechanism.as_ref().unwrap();
assert_eq!(mechanism.handled, Some(false));
assert_eq!(mechanism.mechanism_type, None);
assert_eq!(mechanism.source, None);
assert_eq!(mechanism.synthetic, Some(false));

let stacktrace = props.exception_list[0].stacktrace.as_ref().unwrap();
let stacktrace = exception_list[0].stacktrace.as_ref().unwrap();
assert_eq!(stacktrace.frames.len(), 2);
let RawFrame::JavaScript(frame) = &stacktrace.frames[0];

Expand Down Expand Up @@ -144,7 +130,7 @@ mod test {

let props: Result<ErrProps, Error> = serde_json::from_str(raw);
assert!(props.is_ok());
assert_eq!(props.unwrap().exception_list.len(), 0);
assert_eq!(props.unwrap().exception_list.unwrap().len(), 0);

let raw: &'static str = r#"{
"$exception_list": [{
Expand Down

0 comments on commit 834aed4

Please sign in to comment.