Skip to content

aggregator

diapason.analytics.aggregator

Per-session aggregator — turns many internal events into one analytics event.

Without this, a single chat (50 inferences, 10 tool calls) would produce ~60 PostHog events. With it, the same chat produces one chat_session_ended event with summary properties — a ~60× reduction that keeps per-DAU event volume in the target zone (~40 events/day).

The aggregator buffers per-session counts in memory, emits on explicit session end, and also emits stale sessions on a background flusher thread (so abandoned sessions don't accumulate forever).

SessionAggregator

Buffers per-session counts; emits chat_session_ended on close.

end_session(session_id)

Emit chat_session_ended for one session and drop the buffer.

shutdown()

Flush every buffered session and stop the flusher thread.