March Docs

Bastion.Telemetry.Aggregator

lib/telemetry_aggregator.march — Bastion.Telemetry.Aggregator

A Vault-backed ring buffer that collects all telemetry events per request and provides a waterfall view. Attaches to the ["bastion"] event prefix so it receives every framework event automatically.

── Usage ──────────────────────────────────────────────────────────────────────

-- At application startup:
Bastion.Telemetry.Aggregator.start(100)

-- In a dashboard handler:
let requests = Bastion.Telemetry.Aggregator.recent_requests(20)
let waterfall = Bastion.Telemetry.Aggregator.request_waterfall(request_id)
let stats = Bastion.Telemetry.Aggregator.counters()

Types

typeEventEntryEventEntry = {#
typeRequestSummaryRequestSummary = {#
typeWaterfallDataWaterfallData = {#
typeCounterSummaryCounterSummary = {#

Functions

fncounterscounters() : CounterSummary#

Compute aggregate counters from the ring buffer.

Returns a record with:
  total           — total number of requests in the buffer
  errors          — count of requests with error: true
  avg_duration_ms — mean duration across all buffered requests

    let c = Bastion.Telemetry.Aggregator.counters()
    c.total           -- Int
    c.errors          -- Int
    c.avg_duration_ms -- Int
fnrecent_requestsrecent_requests(limit : Int) : List(RequestSummary)#

Return the most recent limit RequestSummaries from the ring buffer, newest first.

    let requests = Bastion.Telemetry.Aggregator.recent_requests(20)
fnrequest_waterfallrequest_waterfall(request_id : String) : Option(WaterfallData)#

Look up all events recorded for a specific request and build a WaterfallData.

Returns `Some(WaterfallData)` if the request_id is known, `None` otherwise.

    match Bastion.Telemetry.Aggregator.request_waterfall(id) do
    Some(w) -> render_waterfall(w)
    None    -> send_404(conn)
    end
fnresetreset()#

Clear all aggregator state — both event and request tables.

fnstartstart(max_requests : Int)#

Start the aggregator. Attaches a telemetry handler to all bastion events and initialises the Vault storage tables.

max_requests — how many RequestSummary entries to retain in the ring buffer.
Pass 0 to use the default (100).

    Bastion.Telemetry.Aggregator.start(100)