Batch analytics events into an EventSink and compute stats from it
Maintainer antworten meist innerhalb von 1 Tag
@srujankaleru2007 arbeitet bereits daran.
Seit 21.10.2026.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 78/100
- Issue-Typ
- Feature
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- typescript
Rechercherichtung
Read packages/core/src/analytics/collector.ts and packages/core/src/storage/memory.ts, then compare the existing stats shape and event query API. Implement the buffered sink and stats function in packages/core/src/analytics/sink.ts; use packages/core/tests/analytics/sink.test.ts to cover batching, timers, failures, concurrent flushes, and matching stats. Done when the module is exported, the tests pass, and a minor changeset is added.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Analytics live in an AnalyticsCollector in memory (packages/core/src/analytics/collector.ts), capped at 1000 events and per process, so on serverless the stats only describe one instance. @chatcops/core now has an EventSink interface (packages/core/src/storage/types.ts) that stores can back with Redis, Postgres or D1. Writing every event as its own database call would be slow, so this issue adds a small buffer in front of the sink and a function that turns the sink's counts back into today's stats shape.
What to do
Create packages/core/src/analytics/sink.ts:
export class BufferedEventSink {
constructor(sink: EventSink, options?: { maxBatch?: number; flushMs?: number });
/** Queues an event. Never throws and never waits. */
track(type: string, data?: Record<string, unknown>): void;
/** Writes everything queued. Safe to call any time, including concurrently. */
flush(): Promise<void>;
}
/** The same shape as AnalyticsCollector.getStats(), from the sink's counts. */
export function statsFromSink(sink: EventSink, range: { from: number; to: number }): Promise<AnalyticsStats>;
maxBatchdefaults to 50: reaching it starts a flush right away.flushMsdefaults to 2000: the firsttrackafter an empty buffer starts onesetTimeout. Create the timer only insidetrack, never in the constructor, because Workers forbid timers at global scope. Callunref()on it when it exists (Node), so it doesn't keep a process alive.- A failed
sink.writelogs one line,[chatcops] analytics write failed: <message>, and drops that batch. Analytics must never break a chat. - Two flushes at the same time must not write the same event twice.
statsFromSinkthrows a clear error when the sink has noquery. It countsconversation:startedas conversations,message:sentplusmessage:receivedas messages, andlead:capturedas leads. Keep the existing field names (includingleadsCapture), since people already read them.
Where to look
packages/core/src/analytics/collector.tsandpackages/core/tests/analytics/collector.test.tspackages/core/src/storage/memory.ts(memoryStorage().eventshasquery, use it in the tests)
Acceptance criteria
- New
packages/core/src/analytics/sink.tsandpackages/core/tests/analytics/sink.test.ts, exported from@chatcops/core - Tests (fake timers): flush on
maxBatch, flush onflushMs, no timer before the firsttrack, a failing sink logs and drops, concurrentflush()calls write each event once -
statsFromSinkonmemoryStorage().eventsmatches whatAnalyticsCollector.getStats()gives for the same events - Changeset for
@chatcops/core(minor) -
pnpm test:coverageandpnpm lintpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #<this issue number>. Setup notes (pnpm, build before test) are in CONTRIBUTING.md.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 13
- Forks
- 7
- Ø Merge
- 3 Std. 41 Min.
- Gemergte PRs (30 T.)
- 155
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus codercops/chatcops
-
Document the pre-chat formEvtl. vergeben @masyarakatai hat das vor 5 Tagen übernommen. Offendocumentation good first issue hacktoberfest widget
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
codercops/chatcops#70 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
docs: update the providers page for openai-compatible, registerProvider and provider importsEvtl. vergeben @prakashNalla hat das heute übernommen. Offendocumentation good first issue hacktoberfest website
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
codercops/chatcops#291 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
docs: add a protocol reference page for custom clientsEvtl. vergeben @kachamsiddarth hat das vor 1 Tag übernommen. Offendocumentation good first issue hacktoberfest website
codercops/chatcops#286 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Create @chatcops/store-cloudflare (D1, KV and a Durable Object counter)Evtl. vergeben @bhushan4work hat das heute übernommen. Offenenhancement hacktoberfest help wanted server
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
codercops/chatcops#249 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Create @chatcops/store-sqlite, a store for single-server setupsEvtl. vergeben @srikar-naidu hat das vor 1 Tag übernommen. Offenenhancement hacktoberfest help wanted server
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
codercops/chatcops#247 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in codercops/chatcops
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Renaming a projectOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
equinor/prisma-decision-web#927 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
bigbluebutton/bigbluebutton#26166 ·
Maintainer antworten meist innerhalb von 1 Tag