Skip to content

Commit a3f9e86

Browse files
authored
[crashtracking] Add sig_info and os_info as objects in errors payload (#1350)
first commit Trigger CI Co-authored-by: gyuheon.oh <[email protected]>
1 parent 2b91886 commit a3f9e86

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin_tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ strum = { version = "0.26.2", features = ["derive"] }
2222
libc = "0.2"
2323
nix = { version = "0.29", features = ["signal", "socket"] }
2424
hex = "0.4"
25+
os_info = "3.7.0"
2526

2627
[lib]
2728
bench = false

bin_tests/tests/crashtracker_bin_test.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,11 +1783,39 @@ fn assert_errors_intake_payload(errors_intake_content: &[u8], crash_typ: &str) {
17831783
assert_eq!(payload["ddsource"], "crashtracker");
17841784
assert!(payload["timestamp"].is_number());
17851785
assert!(payload["ddtags"].is_string());
1786+
assert!(
1787+
payload["os_info"].is_object(),
1788+
"os_info missing: {:?}",
1789+
payload
1790+
);
17861791

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

1796+
let os_info_val = &payload["os_info"];
1797+
let expected_os_info = ::os_info::get();
1798+
assert_eq!(
1799+
os_info_val["architecture"].as_str().unwrap_or(""),
1800+
expected_os_info.architecture().unwrap_or("unknown"),
1801+
"mismatched architecture in os_info"
1802+
);
1803+
assert_eq!(
1804+
os_info_val["bitness"].as_str().unwrap_or(""),
1805+
expected_os_info.bitness().to_string(),
1806+
"mismatched bitness in os_info"
1807+
);
1808+
assert_eq!(
1809+
os_info_val["os_type"].as_str().unwrap_or(""),
1810+
expected_os_info.os_type().to_string(),
1811+
"mismatched os_type in os_info"
1812+
);
1813+
assert_eq!(
1814+
os_info_val["version"].as_str().unwrap_or(""),
1815+
expected_os_info.version().to_string(),
1816+
"mismatched version in os_info"
1817+
);
1818+
17911819
let error = &payload["error"];
17921820
assert_eq!(error["source_type"], "Crashtracking");
17931821
assert!(error["type"].is_string()); // Note: "error_type" field is serialized as "type"
@@ -1801,6 +1829,26 @@ fn assert_errors_intake_payload(errors_intake_content: &[u8], crash_typ: &str) {
18011829
assert_eq!(error["is_crash"], true);
18021830
}
18031831

1832+
// Validate sig_info when present
1833+
if payload.get("sig_info").is_some() && payload["sig_info"].is_object() {
1834+
let sig = &payload["sig_info"];
1835+
let expected = match crash_typ {
1836+
"null_deref" | "kill_sigsegv" | "raise_sigsegv" => ("SIGSEGV", libc::SIGSEGV),
1837+
"kill_sigabrt" | "raise_sigabrt" => ("SIGABRT", libc::SIGABRT),
1838+
"kill_sigill" | "raise_sigill" => ("SIGILL", libc::SIGILL),
1839+
"kill_sigbus" | "raise_sigbus" => ("SIGBUS", libc::SIGBUS),
1840+
other => panic!("Unexpected crash_typ: {other}"),
1841+
};
1842+
assert_eq!(
1843+
sig["si_signo"].as_i64().unwrap_or_default(),
1844+
expected.1 as i64
1845+
);
1846+
assert_eq!(
1847+
sig["si_signo_human_readable"].as_str().unwrap_or(""),
1848+
expected.0
1849+
);
1850+
}
1851+
18041852
// Check signal-specific values
18051853
match crash_typ {
18061854
"null_deref" => {

libdd-crashtracker/src/collector/api.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,6 @@ mod tests {
608608
#[cfg_attr(miri, ignore)]
609609
#[cfg(target_os = "linux")]
610610
#[test]
611-
#[ignore]
612611
fn test_waitall_nohang() {
613612
// This test checks whether the crashtracking implementation can cause malformed `waitall()`
614613
// idioms to hang.

libdd-crashtracker/src/crash_info/errors_intake.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use std::time::SystemTime;
55

6-
use crate::SigInfo;
6+
use crate::{OsInfo, SigInfo};
77

88
use super::{build_crash_ping_message, CrashInfo, Experimental, Metadata, StackTrace};
99
use anyhow::Context;
@@ -259,6 +259,9 @@ pub struct ErrorsIntakePayload {
259259
pub error: ErrorObject,
260260
#[serde(skip_serializing_if = "Option::is_none")]
261261
pub trace_id: Option<String>,
262+
pub os_info: OsInfo,
263+
#[serde(skip_serializing_if = "Option::is_none")]
264+
pub sig_info: Option<SigInfo>,
262265
}
263266

264267
#[derive(Debug, Default)]
@@ -404,6 +407,8 @@ impl ErrorsIntakePayload {
404407
None
405408
};
406409

410+
let sig_info = crash_info.sig_info.clone();
411+
407412
Ok(Self {
408413
timestamp,
409414
ddsource: "crashtracker".to_string(),
@@ -418,6 +423,8 @@ impl ErrorsIntakePayload {
418423
experimental: crash_info.experimental.clone(),
419424
},
420425
trace_id: None,
426+
os_info: ::os_info::get().into(),
427+
sig_info,
421428
})
422429
}
423430

@@ -476,7 +483,11 @@ impl ErrorsIntakePayload {
476483
source_type: Some("Crashtracking".to_string()),
477484
experimental: None,
478485
},
486+
sig_info: sig_info.cloned(),
479487
trace_id: None,
488+
// Crash ping does not include os_info, but we can recalculate it here
489+
// so that errors intake crash pings include this information
490+
os_info: ::os_info::get().into(),
480491
})
481492
}
482493
}
@@ -598,6 +609,7 @@ mod tests {
598609
std::env::remove_var("_DD_ERRORS_INTAKE_ENABLED");
599610
}
600611

612+
#[cfg_attr(miri, ignore)]
601613
#[test]
602614
fn test_errors_payload_from_crash_info() {
603615
let crash_info = CrashInfo::test_instance(1);
@@ -628,6 +640,7 @@ mod tests {
628640
assert!(ddtags.contains("si_signo_human_readable:SIGSEGV"));
629641
}
630642

643+
#[cfg_attr(miri, ignore)]
631644
#[test]
632645
fn test_errors_payload_from_crash_ping() {
633646
let metadata = Metadata::test_instance(1);
@@ -657,6 +670,7 @@ mod tests {
657670
assert!(ddtags.contains("si_signo_human_readable:SIGSEGV"));
658671
}
659672

673+
#[cfg_attr(miri, ignore)]
660674
#[test]
661675
fn test_errors_intake_has_all_telemetry_tags() {
662676
let crash_info = CrashInfo::test_instance(1);
@@ -691,6 +705,7 @@ mod tests {
691705
}
692706
}
693707

708+
#[cfg_attr(miri, ignore)]
694709
#[test]
695710
fn test_crash_ping_has_all_telemetry_tags() {
696711
let metadata = Metadata::test_instance(1);

0 commit comments

Comments
 (0)