Skip to main content

zeroclaw_runtime/observability/
runtime_trace.rs

1//! Compatibility shim for the doctor command's log-reading utilities.
2//!
3//! The legacy positional-arg `record_event` shim was retired in favor of
4//! direct `zeroclaw_log::record!` invocations carrying typed attribution
5//! via `attribution_span!`. This module survives only as the doctor
6//! command's path-resolution + load surface; new emission code goes
7//! directly to `zeroclaw_log::record!`.
8
9use std::path::Path;
10
11use zeroclaw_log::LogEvent;
12
13pub use zeroclaw_log::{LogEvent as RuntimeTraceEvent, LogFilter, LogPage};
14
15fn to_log_config(config: &zeroclaw_config::schema::ObservabilityConfig) -> zeroclaw_log::LogConfig {
16    zeroclaw_log::LogConfig {
17        log_persistence: config.log_persistence.clone(),
18        log_persistence_path: config.log_persistence_path.clone(),
19        log_persistence_max_entries: config.log_persistence_max_entries,
20        log_tool_io: config.log_tool_io.clone(),
21        log_tool_io_truncate_bytes: config.log_tool_io_truncate_bytes,
22        log_tool_io_denylist: config.log_tool_io_denylist.clone(),
23    }
24}
25
26/// Initialize log persistence from the observability config.
27pub fn init_from_config(
28    config: &zeroclaw_config::schema::ObservabilityConfig,
29    workspace_dir: &Path,
30) {
31    zeroclaw_log::init_from_config(&to_log_config(config), workspace_dir);
32}
33
34/// Resolve the configured log path (used by the doctor command).
35pub fn resolve_trace_path(
36    config: &zeroclaw_config::schema::ObservabilityConfig,
37    workspace_dir: &Path,
38) -> std::path::PathBuf {
39    let policy = zeroclaw_log::ResolvedPolicy::from_config(&to_log_config(config), workspace_dir);
40    policy.path
41}
42
43/// Load a page of events. Replaces the old `load_events` shape with a
44/// thin wrapper around the new paginated reader. The legacy
45/// `event_filter` (single action match) and `contains` (substring) args
46/// map straight onto the new [`LogFilter`] fields.
47pub fn load_events(
48    path: &Path,
49    limit: usize,
50    event_filter: Option<&str>,
51    contains: Option<&str>,
52) -> anyhow::Result<Vec<LogEvent>> {
53    let filter = LogFilter {
54        action: event_filter.map(str::to_string),
55        q: contains.map(str::to_string),
56        ..LogFilter::default()
57    };
58    let page = zeroclaw_log::load_page(path, &filter, limit)?;
59    Ok(page.events)
60}
61
62/// Lookup a single event by id.
63pub fn find_event_by_id(path: &Path, id: &str) -> anyhow::Result<Option<LogEvent>> {
64    zeroclaw_log::find_event_by_id(path, id)
65}