aggregator
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).
Classes¶
SessionAggregator
¶
SessionAggregator(client: 'AnalyticsClient', *, idle_timeout_s: float = _IDLE_TIMEOUT_S, flusher_tick_s: float = _FLUSHER_TICK_S)
Buffers per-session counts; emits chat_session_ended on close.
Source code in src/openjarvis/analytics/aggregator.py
Functions¶
end_session
¶
Emit chat_session_ended for one session and drop the buffer.
Source code in src/openjarvis/analytics/aggregator.py
shutdown
¶
Flush every buffered session and stop the flusher thread.