Nous.Workflow.Trace (nous v0.16.0)

View Source

Records execution traces for workflow debugging and observability.

A trace is an ordered list of node executions with timing, status, and output summaries. Traces are accumulated in-memory during execution and returned as part of the workflow state metadata.

Example

{:ok, state} = Nous.Workflow.run(graph, %{}, trace: true)
trace = state.metadata.trace

for entry <- trace.entries do
  IO.puts "#{entry.node_id} (#{entry.node_type}): #{entry.status} in #{entry.duration_ms}ms"
end

Summary

Functions

Create a new empty trace.

Returns the number of nodes executed.

Returns the total execution time in milliseconds.

Types

entry()

@type entry() :: %{
  node_id: String.t(),
  node_type: atom(),
  started_at: DateTime.t(),
  completed_at: DateTime.t() | nil,
  status: :completed | :failed | :skipped | :suspended,
  duration_ms: non_neg_integer(),
  error: term() | nil
}

t()

@type t() :: %Nous.Workflow.Trace{
  entries: [entry()],
  run_id: String.t(),
  started_at: DateTime.t()
}

Functions

new()

@spec new() :: t()

Create a new empty trace.

node_count(trace)

@spec node_count(t()) :: non_neg_integer()

Returns the number of nodes executed.

record(trace, node_id, node_type, duration_ns, status, error \\ nil)

@spec record(
  t(),
  String.t(),
  atom(),
  non_neg_integer(),
  :completed | :failed | :skipped | :suspended,
  term()
) :: t()

Record a completed node execution.

total_duration_ms(trace)

@spec total_duration_ms(t()) :: non_neg_integer()

Returns the total execution time in milliseconds.