Skip to content

Commit 53dd5eb

Browse files
authored
feat(crashtracking)!: add experimental frame count field (#2099)
[PROF-15014](https://datadoghq.atlassian.net/jira/software/c/projects/PROF/boards/11?selectedIssue=PROF-15014) # What does this PR do? It may be useful to filter crash reports on number of fields. Add an experimental field so that we can check this # Motivation What inspired you to submit this pull request? # Additional Notes Anything else we should know when reviewing? # How to test the change? Describe here in detail how the change can be validated. [PROF-15014]: https://datadoghq.atlassian.net/browse/PROF-15014?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 382a087 commit 53dd5eb

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

docs/RFCs/artifacts/crashtracker-unified-runtime-stack-schema-v1_8.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@
185185
"type": "string"
186186
}
187187
},
188+
"frame_count": {
189+
"type": [
190+
"integer",
191+
"null"
192+
],
193+
"format": "uint",
194+
"minimum": 0.0
195+
},
188196
"runtime_stack": {
189197
"anyOf": [
190198
{

libdd-crashtracker/src/crash_info/builder.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ impl CrashInfoBuilder {
242242
Ok(())
243243
}
244244

245+
pub fn with_experimental_frame_count(&mut self, frame_count: usize) -> anyhow::Result<()> {
246+
if let Some(experimental) = &mut self.experimental {
247+
experimental.frame_count = Some(frame_count);
248+
} else {
249+
self.experimental = Some(Experimental::new().with_frame_count(frame_count));
250+
}
251+
Ok(())
252+
}
253+
245254
pub fn with_kind(&mut self, kind: ErrorKind) -> anyhow::Result<()> {
246255
self.error.with_kind(kind)
247256
}
@@ -654,4 +663,45 @@ mod tests {
654663
"version should not be 'Unknown'"
655664
);
656665
}
666+
667+
#[test]
668+
fn test_with_experimental_frame_count_sets_field() {
669+
let mut builder = CrashInfoBuilder::new();
670+
builder.with_kind(ErrorKind::UnixSignal).unwrap();
671+
672+
let frame1 = StackFrame::test_instance(1);
673+
let frame2 = StackFrame::test_instance(2);
674+
builder.error.with_stack_frame(frame1, true).unwrap();
675+
builder.error.with_stack_frame(frame2, false).unwrap();
676+
677+
let count = builder
678+
.error
679+
.stack
680+
.as_ref()
681+
.map(|s| s.frames.len())
682+
.unwrap_or(0);
683+
builder.with_experimental_frame_count(count).unwrap();
684+
685+
let crash_info = builder.build().unwrap();
686+
let experimental = crash_info.experimental.expect("experimental should be set");
687+
assert_eq!(experimental.frame_count, Some(2));
688+
}
689+
690+
#[test]
691+
fn test_with_experimental_frame_count_zero_when_no_stack() {
692+
let mut builder = CrashInfoBuilder::new();
693+
builder.with_kind(ErrorKind::UnixSignal).unwrap();
694+
695+
let count = builder
696+
.error
697+
.stack
698+
.as_ref()
699+
.map(|s| s.frames.len())
700+
.unwrap_or(0);
701+
builder.with_experimental_frame_count(count).unwrap();
702+
703+
let crash_info = builder.build().unwrap();
704+
let experimental = crash_info.experimental.expect("experimental should be set");
705+
assert_eq!(experimental.frame_count, Some(0));
706+
}
657707
}

libdd-crashtracker/src/crash_info/experimental.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub struct Experimental {
1212
pub additional_tags: Vec<String>,
1313
#[serde(default, skip_serializing_if = "Option::is_none")]
1414
pub runtime_stack: Option<RuntimeStack>,
15+
#[serde(default, skip_serializing_if = "Option::is_none")]
16+
pub frame_count: Option<usize>,
1517
}
1618

1719
impl Experimental {
@@ -28,12 +30,18 @@ impl Experimental {
2830
self.runtime_stack = Some(runtime_stack);
2931
self
3032
}
33+
34+
pub fn with_frame_count(mut self, frame_count: usize) -> Self {
35+
self.frame_count = Some(frame_count);
36+
self
37+
}
3138
}
3239

3340
impl UnknownValue for Experimental {
3441
fn unknown_value() -> Self {
3542
Self {
3643
additional_tags: vec![],
44+
frame_count: None,
3745
runtime_stack: None,
3846
}
3947
}

libdd-crashtracker/src/receiver/receive_report.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,15 @@ pub(crate) async fn receive_report_from_stream(
537537
}
538538
}
539539

540+
builder.with_experimental_frame_count(
541+
builder
542+
.error
543+
.stack
544+
.as_ref()
545+
.map(|s| s.frames.len())
546+
.unwrap_or(0),
547+
)?;
548+
540549
let crash_info = builder.build()?;
541550

542551
if crash_info.incomplete {

0 commit comments

Comments
 (0)