pub struct WorkflowTracker { /* private fields */ }Expand description
Aggregates cost, token, and duration metrics for a named workflow.
Create one tracker per workflow run with WorkflowTracker::new, record
each step with record_shell or
record_agent, then call
summary to emit a structured log line.
Implementations§
Source§impl WorkflowTracker
impl WorkflowTracker
Sourcepub fn new(name: &str) -> Self
pub fn new(name: &str) -> Self
Create a new tracker for a workflow with the given name.
The wall-clock timer starts immediately.
Sourcepub fn max_steps(self, limit: usize) -> Self
pub fn max_steps(self, limit: usize) -> Self
Set the maximum number of steps to retain.
When exceeded, the oldest step is removed. Defaults to 10 000.
Sourcepub fn record_shell(&mut self, name: &str, output: &ShellOutput)
pub fn record_shell(&mut self, name: &str, output: &ShellOutput)
Record a completed shell step.
Extracts the duration from the ShellOutput. Shell steps have no
associated cost or token counts.
Sourcepub fn record_http(&mut self, name: &str, output: &HttpOutput)
pub fn record_http(&mut self, name: &str, output: &HttpOutput)
Record a completed HTTP step.
Extracts the duration from the HttpOutput. HTTP steps have no
associated cost or token counts.
Sourcepub fn record_agent(&mut self, name: &str, result: &AgentResult)
pub fn record_agent(&mut self, name: &str, result: &AgentResult)
Record a completed agent step.
Extracts duration, cost, and token counts from the AgentResult.
Sourcepub fn total_cost_usd(&self) -> f64
pub fn total_cost_usd(&self) -> f64
Return the sum of all agent step costs in USD.
Steps that did not report a cost (including all shell steps) are skipped.
Sourcepub fn total_input_tokens(&self) -> u64
pub fn total_input_tokens(&self) -> u64
Return the sum of all input tokens across agent steps.
Sourcepub fn total_output_tokens(&self) -> u64
pub fn total_output_tokens(&self) -> u64
Return the sum of all output tokens across agent steps.
Sourcepub fn total_duration_ms(&self) -> u64
pub fn total_duration_ms(&self) -> u64
Return the wall-clock duration since the tracker was created, in milliseconds.
Sourcepub fn step_count(&self) -> usize
pub fn step_count(&self) -> usize
Return the number of recorded steps (shell + agent).
Sourcepub fn summary(&self)
pub fn summary(&self)
Emit a structured log summary of the entire workflow and each step.
Uses tracing::info! to log one line for the workflow totals and one
line per step with its kind, duration, cost, and token counts.