Commit 2136989
authored
[kernel-1310] browser telemetry - CLI integration (#168)
Adds browser telemetry to the CLI:
- `kernel browsers create --telemetry=all|off|<list>`
- `kernel browsers update <id> --telemetry=all|off|<list>` (partial —
unspecified categories retain state)
- `kernel browsers telemetry stream <id>` with `--categories`,
`--types`, `--seq` (Last-Event-ID resume), `-o json` (NDJSON)
Full test matrix →
https://gist.github.com/archandatta/f27eb3ea93d58e932b9fd9a7b7b9090f
## Essential run steps to validate
Build:
```bash
go build -o /tmp/kernel ./cmd/kernel
export KERNEL_API_KEY=<your key>
```
**1. Config (create / update / get):**
```bash
# create with all categories enabled
ID=$(/tmp/kernel browsers create --telemetry=all -o json | jq -r .session_id)
# verify on the session
/tmp/kernel browsers get $ID -o json | jq .telemetry
# partial update — only network is changed, others retain state
/tmp/kernel browsers update $ID --telemetry=network=off
/tmp/kernel browsers get $ID -o json | jq .telemetry
# disable everything
/tmp/kernel browsers update $ID --telemetry=off
```
**2. Live stream (text + JSON):**
```bash
# in terminal A — start streaming
/tmp/kernel browsers update $ID --telemetry=all
/tmp/kernel browsers telemetry stream $ID
# in terminal B — drive traffic via CDP (use any Playwright/CDP client) to https://kernel.sh
# events appear in terminal A: 15:04:05<TAB>[network]<TAB>network_response
```
**3. Filters:**
```bash
/tmp/kernel browsers telemetry stream $ID --categories=network
/tmp/kernel browsers telemetry stream $ID --categories=system # monitor_* events
/tmp/kernel browsers telemetry stream $ID --types=network_response
/tmp/kernel browsers telemetry stream $ID -o json # NDJSON envelopes
```
**4. Resume from sequence:**
```bash
# pull a seq from JSON output, then resume
/tmp/kernel browsers telemetry stream $ID --seq=1 # earliest replay (resumes after seq 1; event #1 itself is not replayable)
/tmp/kernel browsers telemetry stream $ID --seq=574 # from a specific event
```
**5. Validation paths (all should error cleanly):**
```bash
/tmp/kernel browsers create --telemetry=garbage # invalid assignment
/tmp/kernel browsers create --telemetry=foo=on # unknown category
/tmp/kernel browsers create --telemetry=network=yes # invalid value
/tmp/kernel browsers telemetry stream $ID --seq=-50 # negative seq rejected
/tmp/kernel browsers telemetry stream $ID --output=yaml # unsupported output
```
Cleanup:
```bash
/tmp/kernel browsers delete $ID
```
## Tests
- 14 unit tests under `cmd/browsers_telemetry_test.go` (`go test
./cmd/...`)
- Full end-to-end matrix run against prod API → see linked gist
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> CLI-only feature wiring to existing browser APIs; no auth or core
infra changes, with broad unit test coverage for parsing and streaming
behavior.
>
> **Overview**
> Adds **browser telemetry** to the Kernel CLI: configure it on session
**create** and **update**, and **stream** live events from a running
session.
>
> **Configuration** — New `--telemetry` on `browsers create` and
`browsers update` accepts `all`, `off`, or per-category lists
(`network=on,page=off`). Per-category updates only send named categories
so the API can merge; `all`/`off` set the global `Enabled` flag.
`browsers update` now allows telemetry-only updates (no
proxy/profile/viewport required).
>
> **Streaming** — New `browsers telemetry stream <id>` uses the SDK SSE
client, resolves the session ID, supports `--categories`, `--types`,
`--seq` (Last-Event-ID resume), human-readable lines or `-o json` NDJSON
via new `PrintCompactJSONLine`. Client-side filtering and category
inference (wire `category` or type-prefix, with `monitor_*` → `system`).
>
> **Docs & tests** — README documents flags and telemetry section; unit
tests cover param wire shapes, stream validation, filters, and
create/update telemetry mapping.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
0e33313. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 68c4770 commit 2136989
6 files changed
Lines changed: 729 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
215 | 219 | | |
216 | 220 | | |
217 | 221 | | |
218 | 222 | | |
219 | 223 | | |
220 | 224 | | |
221 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
222 | 231 | | |
223 | 232 | | |
224 | 233 | | |
| |||
281 | 290 | | |
282 | 291 | | |
283 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
284 | 310 | | |
285 | 311 | | |
286 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
| 206 | + | |
205 | 207 | | |
206 | 208 | | |
207 | 209 | | |
| |||
215 | 217 | | |
216 | 218 | | |
217 | 219 | | |
| 220 | + | |
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
| |||
331 | 334 | | |
332 | 335 | | |
333 | 336 | | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
413 | 424 | | |
414 | 425 | | |
415 | 426 | | |
| |||
576 | 587 | | |
577 | 588 | | |
578 | 589 | | |
579 | | - | |
580 | | - | |
| 590 | + | |
| 591 | + | |
581 | 592 | | |
582 | 593 | | |
583 | 594 | | |
| |||
602 | 613 | | |
603 | 614 | | |
604 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
605 | 625 | | |
606 | 626 | | |
607 | 627 | | |
| |||
2229 | 2249 | | |
2230 | 2250 | | |
2231 | 2251 | | |
| 2252 | + | |
2232 | 2253 | | |
2233 | 2254 | | |
2234 | 2255 | | |
| |||
2494 | 2515 | | |
2495 | 2516 | | |
2496 | 2517 | | |
| 2518 | + | |
2497 | 2519 | | |
2498 | 2520 | | |
2499 | 2521 | | |
| |||
2520 | 2542 | | |
2521 | 2543 | | |
2522 | 2544 | | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
2523 | 2554 | | |
2524 | 2555 | | |
2525 | 2556 | | |
| |||
2563 | 2594 | | |
2564 | 2595 | | |
2565 | 2596 | | |
| 2597 | + | |
2566 | 2598 | | |
2567 | 2599 | | |
2568 | 2600 | | |
| |||
2672 | 2704 | | |
2673 | 2705 | | |
2674 | 2706 | | |
| 2707 | + | |
2675 | 2708 | | |
2676 | 2709 | | |
2677 | 2710 | | |
| |||
2730 | 2763 | | |
2731 | 2764 | | |
2732 | 2765 | | |
| 2766 | + | |
2733 | 2767 | | |
2734 | 2768 | | |
2735 | 2769 | | |
| |||
2742 | 2776 | | |
2743 | 2777 | | |
2744 | 2778 | | |
| 2779 | + | |
2745 | 2780 | | |
2746 | 2781 | | |
2747 | 2782 | | |
| |||
0 commit comments