Skip to content

[kernel-1310] browser telemetry - CLI integration#168

Open
archandatta wants to merge 29 commits into
mainfrom
archand/kernel-1116/browser-events
Open

[kernel-1310] browser telemetry - CLI integration#168
archandatta wants to merge 29 commits into
mainfrom
archand/kernel-1116/browser-events

Conversation

@archandatta
Copy link
Copy Markdown
Contributor

@archandatta archandatta commented May 27, 2026

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:

go build -o /tmp/kernel ./cmd/kernel
export KERNEL_API_KEY=<your key>

1. Config (create / update / get):

# 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):

# 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:

/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:

# pull a seq from JSON output, then resume
/tmp/kernel browsers telemetry stream $ID --seq=0     # from beginning of retention
/tmp/kernel browsers telemetry stream $ID --seq=574   # from a specific event

5. Validation paths (all should error cleanly):

/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:

/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

Note

Medium Risk
Enables collection and live streaming of browser activity (network, console, page, etc.); behavior depends on correct API merge semantics for partial --telemetry updates.

Overview
Adds browser telemetry to the CLI: configure it on session create and update via --telemetry=all, --telemetry=off, or per-category lists like network=on,page=off (partial updates only touch named categories; all/off reset the whole config).

Introduces kernel browsers telemetry stream <id> for live SSE events with optional --categories, --types, --seq (Last-Event-ID resume), human-readable lines or -o json NDJSON via new PrintCompactJSONLine. README documents the commands and flags; unit tests cover parsing, wire encoding, streaming, and create/update wiring.

Reviewed by Cursor Bugbot for commit 93d3168. Bugbot is set up for automated code reviews on this repo. Configure here.

archandatta and others added 27 commits May 27, 2026 13:11
knownTelemetryTypes was 22 hardcoded strings that would silently drift
as new server-side event types shipped. Drop the warning; unrecognized
--types values simply produce no matches, which is obvious.

knownTelemetryCategories was settableCategories + "system" with no
single source of truth. Remove it; validate --categories against
settableCategories with an explicit carve-out for "system".
- mention browsers create as a --telemetry surface (not just update)
- document partial-update semantics for per-category config
- note default --seq behavior (omit to stream from now)
- correct the default output example to call out tab-separated format
@archandatta archandatta marked this pull request as ready for review May 28, 2026 14:10
@archandatta archandatta requested review from rgarcia and removed request for rgarcia May 28, 2026 14:10
@archandatta archandatta requested review from Sayan- and rgarcia May 28, 2026 14:10
@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR modifies CLI commands (cmd/kernel) for browser telemetry, not the kernel API endpoints (packages/api/cmd/api/) or Temporal workflows (packages/api/lib/temporal) specified in the filter.

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread cmd/browsers_telemetry.go
return false
}
return true
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function shouldEmit defined but never called in production

Low Severity

The shouldEmit helper function is defined and unit-tested but never called from production code. TelemetryStream duplicates the exact same filtering logic inline (checking in.Categories and in.Types with slices.Contains) instead of calling shouldEmit. This means the tested function and the actual streaming behavior can drift independently — a fix applied to one won't propagate to the other.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 26e6b5b. Configure here.

Copy link
Copy Markdown
Contributor

@Sayan- Sayan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integration looks good overall!

Comment thread cmd/browsers_telemetry.go Outdated
Comment thread cmd/browsers_telemetry.go
…eam --categories

- buildTelemetryParam: drop Enabled=true from the per-category branch so the
  request goes through the API's merge path. Previously, enabled=true +
  browser={...} collided with the enable-all encoding and was treated as a
  replace, defaulting unmentioned categories back to on.
- TelemetryStream: validate --categories against the known set (console,
  interaction, network, page, system) and error on typos. Mirrors the
  config-side validation in parseTelemetryCategories.
- Tests: cover the three wire-encoding shapes for buildTelemetryParam; flip
  the create-with-categories test to assert Enabled is unset; flip the
  unknown-category stream test to assert error.
@archandatta archandatta requested a review from Sayan- May 29, 2026 11:04
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 93d3168. Configure here.

Comment thread cmd/browsers_telemetry.go
telemetryStream.Flags().StringSlice("categories", []string{}, "Filter by API event category (console,network,page,interaction,system); system covers all monitor_* events")
telemetryStream.Flags().StringSlice("types", []string{}, "Filter by event type (e.g. network_response,console_error)")
telemetryStream.Flags().Int64("seq", -1, "Resume stream from sequence number (Last-Event-ID); 0 means from the beginning")
telemetryStream.Flags().StringP("output", "o", "", "Output format: json for newline-delimited JSON envelopes")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Telemetry stream uses inline output flag instead of shared helper

Low Severity

The telemetry stream command defines its output flag inline via StringP("output", "o", "", "Output format: json for newline-delimited JSON envelopes") and validates it with a hand-rolled check (if in.Output != "" && in.Output != "json"). Every other command in cmd/ uses addJSONOutputFlag(cmd) for flag registration and validateJSONOutput(output) for validation. The error message also drifts from the standard format used by ValidateJSONOutput.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by learned rule: Use shared JSON output helpers in CLI commands

Reviewed by Cursor Bugbot for commit 93d3168. Configure here.

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.

2 participants