feat(kiloclaw): add Cloudflare Analytics Engine instrumentation#1311
Open
pandemicsyn wants to merge 4 commits intomainfrom
Open
feat(kiloclaw): add Cloudflare Analytics Engine instrumentation#1311pandemicsyn wants to merge 4 commits intomainfrom
pandemicsyn wants to merge 4 commits intomainfrom
Conversation
added 2 commits
March 19, 2026 21:30
Add analytics tracking across three layers: HTTP routes, DO lifecycle events, and reconciliation corrective actions. Uses a single dataset (kiloclaw_events) with 13 blobs, 2 doubles, and 1 index. HTTP layer: timingMiddleware + per-route instrumented() wrappers for admin/kiloclaw routes, Hono middleware for platform routes. parseBody() sets userId on context so the middleware captures it for POST/PATCH. DO lifecycle: emitEvent() helper with Omit<> pattern. Tracks provision (with duration), start (with startup time), stop/destroy (with machine uptime via value double). Reconciliation: events for status drift, volume repair, metadata recovery, API key refresh, stale provision destroy, bound machine recovery, and destroy finalization. Only emitted on corrective actions.
Add performance.now() timing to four reconcile corrective action events: - reconcile.api_key_refreshed: mint + Fly update + push flow - reconcile.metadata_recovery: listMachines + candidate selection + persist - reconcile.volume_repaired: ensureVolume replacement flow - reconcile.bound_machine_recovery: getVolume + state persistence
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (13 files)
Reviewed by gpt-5.4-20260305 · 195,735 tokens |
Introduce ReconcileContext that dual-writes every reconcileLog call to both console JSON and Cloudflare Analytics Engine. This replaces the previous approach of selectively instrumenting ~10 reconcile events with full coverage of all ~43 events. Key changes: - Add ReconcileContext type and createReconcileContext() factory in log.ts - Replace reason+env parameter threading with single rctx across all reconcile functions - Remove all manual writeEvent calls from reconcile.ts - Validate userId via setValidatedQueryUserId() in platform GET/DELETE routes instead of reading raw query params in analytics middleware - Skip analytics for non-user-scoped platform routes (e.g. /versions) - Truncate error messages to 200 chars in analytics middleware
jeanduplessis
approved these changes
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add Cloudflare Analytics Engine instrumentation to KiloClaw across HTTP routes, DO lifecycle, and reconciliation paths, then refactor reconcile telemetry to use a unified
ReconcileContextthat dual-writes console reconcile logs and AE events.timingMiddleware;instrumented()wrappers for/api/admin/*and/api/kiloclaw/*; platform middleware emits request events and now records validated query/body-derived user context.emitEvent()inKiloClawInstancerecords provision/start/stop/destroy lifecycle events with duration/value metrics.rctx.log(...)withreconcile.{action}naming and common state-derived dimensions; includes duration/error/value fields where applicable.[unserializable error]fallback).Verification
pnpm typecheck(inkiloclaw) — passpnpm test(inkiloclaw) — pass (42files /936tests)pnpm format:checkpnpm lint(monorepo)pnpm typecheck(monorepo)Visual Changes
N/A
Reviewer Notes
src/utils/analytics.tsand shared by HTTP, DO, and reconcile emitters.