Skip to content

Commit 6a02f01

Browse files
authored
chore(crashtracking): add tag for target triple (#1741)
# What does this PR do? At compile time, check target triple. Include this tag when we generate the payload for telemetry and errors intake upload [PROF-14038](https://datadoghq.atlassian.net/jira/software/c/projects/PROF/boards/11?selectedIssue=PROF-14038) # Motivation It would be nice to tag reports based on this; especially given different reliability considerations between musl and glibc crashtracking Trying to check libc is harder because many OS are ambiguous # Additional Notes Anything else we should know when reviewing? # How to test the change? Unit tests. ``` println!( "cargo:rustc-env=TARGET={}", std::env::var("TARGET").unwrap() ); ``` The above always works when run in `build.rs` through cargo. The tests need to confirm that the value set by the build script is included in ddtags [PROF-14038]: https://datadoghq.atlassian.net/browse/PROF-14038?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: gyuheon.oh <gyuheon.oh@datadoghq.com>
1 parent 8f611f3 commit 6a02f01

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

libdd-crashtracker/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ fn build_cpp_file() {
114114

115115
#[cfg(unix)]
116116
fn main() {
117+
println!(
118+
"cargo:rustc-env=TARGET={}",
119+
std::env::var("TARGET").unwrap()
120+
);
121+
117122
cc::Build::new()
118123
.file("src/crash_info/emit_sicodes.c")
119124
.compile("emit_sicodes");
@@ -139,6 +144,11 @@ fn main() {
139144

140145
#[cfg(not(unix))]
141146
fn main() {
147+
println!(
148+
"cargo:rustc-env=TARGET={}",
149+
std::env::var("TARGET").unwrap()
150+
);
151+
142152
// Build CXX bridge if feature is enabled
143153
#[cfg(feature = "cxx")]
144154
build_cxx_bridge();

libdd-crashtracker/src/crash_info/errors_intake.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::time::SystemTime;
55

66
use crate::{OsInfo, SigInfo};
77

8-
use super::{build_crash_ping_message, CrashInfo, Experimental, Metadata, StackTrace};
8+
use super::{
9+
build_crash_ping_message, CrashInfo, Experimental, Metadata, StackTrace, TARGET_TRIPLE,
10+
};
911
use anyhow::Context;
1012
use chrono::{DateTime, Utc};
1113
use http::{uri::PathAndQuery, Uri};
@@ -363,6 +365,7 @@ fn build_crash_info_tags(crash_info: &CrashInfo) -> String {
363365
append_signal_tags(&mut tags, siginfo);
364366
}
365367

368+
tags.push_str(&format!(",target_triple:{TARGET_TRIPLE}"));
366369
tags
367370
}
368371

@@ -456,6 +459,8 @@ impl ErrorsIntakePayload {
456459
append_signal_tags(&mut ddtags, sig_info);
457460
}
458461

462+
ddtags.push_str(&format!(",target_triple:{TARGET_TRIPLE}"));
463+
459464
let (error_type, message) = if let Some(sig_info) = sig_info {
460465
(
461466
Some(format!("{:?}", sig_info.si_signo_human_readable)),
@@ -689,6 +694,7 @@ mod tests {
689694
"si_code_human_readable:SEGV_BNDERR",
690695
"si_signo:11",
691696
"si_signo_human_readable:SIGSEGV",
697+
&format!("target_triple:{}", super::super::TARGET_TRIPLE),
692698
];
693699

694700
let expected_metadata_tags = ["service:foo", "version:bar", "language_name:native"];
@@ -726,8 +732,10 @@ mod tests {
726732
"si_code_human_readable:SEGV_BNDERR",
727733
"si_signo:11",
728734
"si_signo_human_readable:SIGSEGV",
735+
&format!("target_triple:{}", super::super::TARGET_TRIPLE),
729736
];
730737

738+
println!("payload.ddtags: {}", payload.ddtags);
731739
for tag in expected_tags {
732740
assert!(
733741
payload.ddtags.contains(tag),

libdd-crashtracker/src/crash_info/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ mod telemetry;
1717
mod test_utils;
1818
mod unknown_value;
1919

20+
// This is set compile time
21+
pub(crate) const TARGET_TRIPLE: &str = env!("TARGET");
22+
2023
pub use builder::*;
2124
pub use error_data::*;
2225
pub use errors_intake::*;

libdd-crashtracker/src/crash_info/telemetry.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fmt::Write, time::SystemTime};
44

55
use crate::{ErrorKind, SigInfo};
66

7-
use super::{CrashInfo, Metadata};
7+
use super::{CrashInfo, Metadata, TARGET_TRIPLE};
88
use anyhow::Context;
99
use chrono::{DateTime, Utc};
1010
use libdd_common::Endpoint;
@@ -396,6 +396,7 @@ impl TelemetryCrashUploader {
396396
));
397397
}
398398

399+
write!(tags, ",target_triple:{TARGET_TRIPLE}").ok();
399400
self.append_optional_tags(&mut tags);
400401
tags
401402
}
@@ -448,6 +449,7 @@ fn extract_crash_info_tags(crash_info: &CrashInfo) -> anyhow::Result<String> {
448449
siginfo.si_signo_human_readable
449450
)?;
450451
}
452+
write!(&mut tags, ",target_triple:{TARGET_TRIPLE}")?;
451453
Ok(tags)
452454
}
453455

@@ -556,6 +558,7 @@ mod tests {
556558
"si_signo_human_readable:SIGSEGV",
557559
"si_signo:11",
558560
"uuid:1d6b97cb-968c-40c9-af6e-e4b4d71e8781",
561+
&format!("target_triple:{}", super::super::TARGET_TRIPLE),
559562
]),
560563
tags
561564
);

0 commit comments

Comments
 (0)