Commit 4726b96
authored
feat(kiloclaw): add Cloudflare Analytics Engine instrumentation (#1311)
## Summary
Add Cloudflare Analytics Engine instrumentation to KiloClaw across HTTP
routes, DO lifecycle, and reconciliation paths, then refactor reconcile
telemetry to use a unified `ReconcileContext` that dual-writes console
reconcile logs and AE events.
- **HTTP telemetry**: global `timingMiddleware`; `instrumented()`
wrappers for `/api/admin/*` and `/api/kiloclaw/*`; platform middleware
emits request events and now records validated query/body-derived user
context.
- **DO lifecycle telemetry**: `emitEvent()` in `KiloClawInstance`
records provision/start/stop/destroy lifecycle events with
duration/value metrics.
- **Reconcile telemetry**: reconcile call sites now emit consistently
via `rctx.log(...)` with `reconcile.{action}` naming and common
state-derived dimensions; includes duration/error/value fields where
applicable.
- **Hardening**: reconcile analytics error serialization is now guarded
so unserializable error payloads cannot break best-effort analytics
(`[unserializable error]` fallback).
## Verification
- `pnpm typecheck` (in `kiloclaw`) — pass
- `pnpm test` (in `kiloclaw`) — pass (`42` files / `936` tests)
- Pre-push hook (repo root) — pass:
- `pnpm format:check`
- `pnpm lint` (monorepo)
- `pnpm typecheck` (monorepo)
## Visual Changes
N/A
## Reviewer Notes
- Blob layout is centralized in `src/utils/analytics.ts` and shared by
HTTP, DO, and reconcile emitters.
- Platform middleware skips non-error events for routes without user
context (for example version metadata endpoints) to reduce low-signal
telemetry noise.13 files changed
Lines changed: 848 additions & 692 deletions
File tree
- kiloclaw
- src
- durable-objects/kiloclaw-instance
- middleware
- routes
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
102 | 137 | | |
103 | 138 | | |
104 | 139 | | |
105 | 140 | | |
106 | 141 | | |
| 142 | + | |
107 | 143 | | |
108 | 144 | | |
109 | 145 | | |
| |||
295 | 331 | | |
296 | 332 | | |
297 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
298 | 340 | | |
299 | 341 | | |
300 | 342 | | |
| |||
660 | 702 | | |
661 | 703 | | |
662 | 704 | | |
663 | | - | |
| 705 | + | |
664 | 706 | | |
665 | 707 | | |
666 | 708 | | |
| |||
699 | 741 | | |
700 | 742 | | |
701 | 743 | | |
702 | | - | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
703 | 751 | | |
704 | 752 | | |
705 | 753 | | |
| |||
803 | 851 | | |
804 | 852 | | |
805 | 853 | | |
| 854 | + | |
806 | 855 | | |
807 | 856 | | |
808 | 857 | | |
| |||
819 | 868 | | |
820 | 869 | | |
821 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
822 | 877 | | |
823 | 878 | | |
824 | 879 | | |
| |||
902 | 957 | | |
903 | 958 | | |
904 | 959 | | |
| 960 | + | |
| 961 | + | |
905 | 962 | | |
906 | 963 | | |
907 | 964 | | |
| |||
921 | 978 | | |
922 | 979 | | |
923 | 980 | | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
924 | 987 | | |
925 | 988 | | |
926 | 989 | | |
| |||
931 | 994 | | |
932 | 995 | | |
933 | 996 | | |
| 997 | + | |
| 998 | + | |
934 | 999 | | |
935 | 1000 | | |
936 | 1001 | | |
| |||
941 | 1006 | | |
942 | 1007 | | |
943 | 1008 | | |
944 | | - | |
945 | | - | |
946 | | - | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
947 | 1014 | | |
948 | | - | |
949 | | - | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
950 | 1026 | | |
951 | 1027 | | |
952 | 1028 | | |
| |||
1447 | 1523 | | |
1448 | 1524 | | |
1449 | 1525 | | |
1450 | | - | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1451 | 1531 | | |
1452 | 1532 | | |
1453 | 1533 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
30 | 86 | | |
31 | 87 | | |
32 | 88 | | |
| |||
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
0 commit comments