Inner fallible implementation of [`append_agent_trace`].
(record: &TraceRecord, root: &Path)
| 449 | |
| 450 | /// Inner fallible implementation of [`append_agent_trace`]. |
| 451 | fn try_append_agent_trace(record: &TraceRecord, root: &Path) -> std::io::Result<()> { |
| 452 | use std::fs::{self, OpenOptions}; |
| 453 | use std::io::Write; |
| 454 | |
| 455 | let dir = root.join(".agent-trace"); |
| 456 | fs::create_dir_all(&dir)?; |
| 457 | |
| 458 | let path = dir.join("traces.jsonl"); |
| 459 | let mut file = OpenOptions::new().create(true).append(true).open(&path)?; |
| 460 | |
| 461 | let line = serde_json::to_string(record) |
| 462 | .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?; |
| 463 | writeln!(file, "{}", line)?; |
| 464 | |
| 465 | log::debug!( |
| 466 | "agent-trace: appended record {} to {}", |
| 467 | record.id, |
| 468 | path.display() |
| 469 | ); |
| 470 | |
| 471 | Ok(()) |
| 472 | } |
| 473 | |
| 474 | // --------------------------------------------------------------------------- |
| 475 | // Tests |
no test coverage detected