src/pocketflow/observability

Observability module for PocketFlow

Provides structured logging, metrics, and tracing capabilities.

Types

LogLevel = enum
  Debug, Info, Warn, Error, Fatal
Log severity levels
Metric = object
  name*: string
  value*: float
  tags*: TableRef[string, string]
  timestamp*: Time
A metric measurement
Observer = ref object
  metrics*: seq[Metric]
  spans*: seq[Span]
  currentSpan*: Span
Main observability handler
Span = ref object
  name*: string
  startTime*: Time
  endTime*: Time
  tags*: TableRef[string, string]
  metrics*: seq[Metric]
  children*: seq[Span]
A tracing span for measuring operation duration

Vars

globalObserver = Observer(metrics: @[], spans: @[], currentSpan: nil)

Procs

proc finish(span: Span) {....raises: [], tags: [TimeEffect], forbids: [].}
Finishes a span and records its duration
proc getDurationMs(span: Span): float {....raises: [], tags: [], forbids: [].}
Gets the duration of a span in milliseconds
proc getMetricsSummary(): JsonNode {....raises: [KeyError], tags: [], forbids: [].}
Returns a JSON summary of all recorded metrics
proc logStructured(level: LogLevel; message: string;
                   fields: openArray[(string, string)] = []) {....raises: [],
    tags: [], forbids: [].}
Logs a structured message with additional fields
proc newSpan(name: string): Span {....raises: [], tags: [TimeEffect], forbids: [].}
Creates a new tracing span
proc recordMetric(name: string; value: float;
                  tags: openArray[(string, string)] = []) {....raises: [],
    tags: [TimeEffect], forbids: [].}
Records a metric measurement

Templates

template withSpan(name: string; body: untyped)
Template for automatic span management