Skip to content

Commit c476d2a

Browse files
committed
Emit by frame directly
1 parent a9ec43b commit c476d2a

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

datadog-crashtracker/src/receiver/receive_report.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ async fn send_crash_ping_to_url(
4141
uploader.upload_crash_ping(&crash_ping).await
4242
}
4343

44+
/// Create fully qualified function name
45+
fn create_qualified_function_name() -> String {
46+
return "hi".to_string();
47+
}
48+
4449
/// The crashtracker collector sends data in blocks.
4550
/// This enum tracks which block we're currently in, and, for multi-line blocks,
4651
/// collects the partial data until the block is closed and it can be appended

datadog-crashtracker/src/runtime_callback.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,43 @@ unsafe fn emit_frame_as_json(
355355
// to a valid RuntimeStackFrame.
356356
let frame_ref = &*frame;
357357

358-
// TODO: this allocates a new StackFrame. Avoid this by just emitting the JSON directly here.
359-
let stack_frame: StackFrame = frame_ref.into();
358+
write!(writer, "{{")?;
360359

361-
// Serialize to JSON and write
362-
let json = serde_json::to_string(&stack_frame).map_err(std::io::Error::other)?;
363-
writeln!(writer, "{}", json)?;
360+
let mut first_field = true;
361+
362+
if let Ok(Some(function_name)) = frame_ref.function_name.try_to_string_option() {
363+
write!(
364+
writer,
365+
"\"function\": \"{}\"",
366+
function_name.replace('"', "\\\"")
367+
)?;
368+
first_field = false;
369+
}
370+
371+
if let Ok(Some(file_name)) = frame_ref.file_name.try_to_string_option() {
372+
if !first_field {
373+
write!(writer, ", ")?;
374+
}
375+
write!(writer, "\"file\": \"{}\"", file_name.replace('"', "\\\""))?;
376+
first_field = false;
377+
}
378+
379+
if frame_ref.line_number != 0 {
380+
if !first_field {
381+
write!(writer, ", ")?;
382+
}
383+
write!(writer, "\"line\": {}", frame_ref.line_number)?;
384+
first_field = false;
385+
}
386+
387+
if frame_ref.column_number != 0 {
388+
if !first_field {
389+
write!(writer, ", ")?;
390+
}
391+
write!(writer, "\"column\": {}", frame_ref.column_number)?;
392+
}
393+
394+
writeln!(writer, "}}")?;
364395
Ok(())
365396
}
366397

0 commit comments

Comments
 (0)