Skip to content
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
80 changes: 48 additions & 32 deletions bin_tests/tests/crashtracker_bin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,11 @@ fn assert_telemetry_message(crash_telemetry: &[u8], crash_typ: &str) {
);
assert_eq!(telemetry_payload["payload"].as_array().unwrap().len(), 1);

let tags = telemetry_payload["payload"][0]["tags"]
.as_str()
.unwrap()
let log_entry = &telemetry_payload["payload"][0];
let tags_raw = log_entry["tags"].as_str().unwrap();
let is_crash_ping = tags_raw.contains("is_crash_ping:true");

let tags = tags_raw
.split(',')
.filter(|t| !t.starts_with("uuid:"))
.collect::<std::collections::HashSet<_>>();
Expand Down Expand Up @@ -918,7 +920,48 @@ fn assert_telemetry_message(crash_telemetry: &[u8], crash_typ: &str) {
_ => panic!("{crash_typ}"),
}

assert_eq!(telemetry_payload["payload"][0]["is_sensitive"], true);
assert_eq!(log_entry["is_sensitive"], true);

if !is_crash_ping {
let message_str = log_entry["message"]
.as_str()
.expect("Crash report telemetry should have a JSON message body");
let crash_report_json: Value = serde_json::from_str(message_str)
.expect("Crash report telemetry message should be valid JSON");

assert_os_info_matches(
&crash_report_json["os_info"],
"telemetry crash report message",
);
}
}

fn assert_os_info_matches(os_info_val: &Value, context: &str) {
assert!(
os_info_val.is_object(),
"os_info missing in {context}: {os_info_val:?}"
);
let expected_os_info = ::os_info::get();
assert_eq!(
os_info_val["architecture"].as_str().unwrap_or(""),
expected_os_info.architecture().unwrap_or("unknown"),
"mismatched architecture in os_info for {context}"
);
assert_eq!(
os_info_val["bitness"].as_str().unwrap_or(""),
expected_os_info.bitness().to_string(),
"mismatched bitness in os_info for {context}"
);
assert_eq!(
os_info_val["os_type"].as_str().unwrap_or(""),
expected_os_info.os_type().to_string(),
"mismatched os_type in os_info for {context}"
);
assert_eq!(
os_info_val["version"].as_str().unwrap_or(""),
expected_os_info.version().to_string(),
"mismatched version in os_info for {context}"
);
}

#[test]
Expand Down Expand Up @@ -1305,39 +1348,12 @@ fn assert_errors_intake_payload(errors_intake_content: &[u8], crash_typ: &str) {
assert_eq!(payload["ddsource"], "crashtracker");
assert!(payload["timestamp"].is_number());
assert!(payload["ddtags"].is_string());
assert!(
payload["os_info"].is_object(),
"os_info missing: {:?}",
payload
);
assert_os_info_matches(&payload["os_info"], "errors intake payload");

let ddtags = payload["ddtags"].as_str().unwrap();
assert!(ddtags.contains("service:foo"));
assert!(ddtags.contains("uuid:"));

let os_info_val = &payload["os_info"];
let expected_os_info = ::os_info::get();
assert_eq!(
os_info_val["architecture"].as_str().unwrap_or(""),
expected_os_info.architecture().unwrap_or("unknown"),
"mismatched architecture in os_info"
);
assert_eq!(
os_info_val["bitness"].as_str().unwrap_or(""),
expected_os_info.bitness().to_string(),
"mismatched bitness in os_info"
);
assert_eq!(
os_info_val["os_type"].as_str().unwrap_or(""),
expected_os_info.os_type().to_string(),
"mismatched os_type in os_info"
);
assert_eq!(
os_info_val["version"].as_str().unwrap_or(""),
expected_os_info.version().to_string(),
"mismatched version in os_info"
);

let error = &payload["error"];
assert_eq!(error["source_type"], "Crashtracking");
assert!(error["type"].is_string()); // Note: "error_type" field is serialized as "type"
Expand Down
1 change: 1 addition & 0 deletions libdd-crashtracker/src/receiver/receive_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ pub(crate) async fn receive_report_from_stream(

// For now, we only support Signal based crash detection in the receiver.
builder.with_kind(ErrorKind::UnixSignal)?;
builder.with_os_info_this_machine()?;

// Without a config, we don't even know the endpoint to transmit to. Not much to do to recover.
let config = config.context("Missing crashtracker configuration")?;
Expand Down
Loading