Skip to content

feat(server): write analytics to the storage event sink - #316

Merged
anurag629 merged 1 commit into
devfrom
feat/server-analytics-sink
Oct 22, 2026
Merged

anurag629 merged 1 commit into
devfrom
feat/server-analytics-sink

Conversation

@anurag629

Copy link
Copy Markdown
Member

Slice T3 of P1 (F-03 task 5), on top of BufferedEventSink and statsFromSink from #314 (#246).

  • With analytics: true and a storage that has events, every event also goes through a BufferedEventSink on the store's sink. The in-process AnalyticsCollector keeps counting as before.
  • The buffer is flushed after lead webhooks, before the reply's stream ends, the same way webhooks are awaited. That way Vercel and Workers don't cut off the write once the response is done. A failed write is logged ([chatcops] analytics write failed: ...) and the chat still answers.
  • New analyticsStats(range?) on the handler: counts from the sink when it has query (so it covers every instance), flushing first, for the last 30 days by default. It falls back to the process collector for a sink that can only be written to. getAnalytics() is unchanged and describes this process.
  • chatcopsAnalyticsHandler (Express) uses it, with ?from= and ?to= in milliseconds. A range that isn't a number gets 400 invalid_range, a sink that can't be read gets 500 with a log line, and the bearer check is unchanged. The handler is now async, so the existing tests await it.
  • Docs: the analytics page covers stats from the store and the range, and its sample mounts with app.use.

Checks: build, typecheck, pnpm test:coverage (1123 passed; 8 new in server/tests/analytics-sink.test.ts, including two handlers sharing one store the way two serverless instances would), lint at the dev baseline, website build.

@anurag629
anurag629 merged commit 7c27f8c into dev Oct 22, 2026
5 checks passed
@anurag629
anurag629 deleted the feat/server-analytics-sink branch October 22, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant