Skip to content

feat: implement proxy-based telemetry for VS Code extension#410

Merged
markijbema merged 25 commits intodevfrom
mark/telemetry-implementation
Feb 18, 2026
Merged

feat: implement proxy-based telemetry for VS Code extension#410
markijbema merged 25 commits intodevfrom
mark/telemetry-implementation

Conversation

@markijbema
Copy link
Contributor

@markijbema markijbema commented Feb 18, 2026

Summary

Implements proxy-based telemetry for the VS Code extension, forwarding events through the CLI server to the kilo-telemetry package (PostHog).

Architecture

Webview (SolidJS)  →  postMessage  →  Extension Host  →  HTTP POST /telemetry/capture  →  CLI Server  →  kilo-telemetry (PostHog)

The extension never talks to PostHog directly. All telemetry flows through the CLI server, which owns the PostHog client via @kilocode/kilo-telemetry.

Limitations

I only added the telemetry for events which arent happening in the CLI; this means that some classical events are missing because the cli does not emit them. I think we need to look at how to get that more in sync between CLI and vscode, as i don't think we want that as a separate code path in the vscode extension.

Fixes #371

@markijbema markijbema changed the title feat: implement telemetry for vscode extension feat: implement proxy-based telemetry for VS Code extension Feb 18, 2026
2. **Minimize changes to shared files** - When you must modify files that exist in upstream opencode, keep changes as small and isolated as possible.

3. **Use `kilocode_change` markers** - When modifying shared code, mark your changes with `kilocode_change` comments so they can be easily identified during merges.
Do not use these markers in files within directories with kilo in the name
Copy link
Contributor Author

Choose a reason for hiding this comment

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

got annoyed by this

@markijbema markijbema force-pushed the mark/telemetry-implementation branch from 1e13cc9 to d862296 Compare February 18, 2026 14:39
The PostHogSpanExporter and TracerSetup had hardcoded 'kilo-cli' and
process.platform values, bypassing the env var overrides. Now appName,
appVersion, and platform flow from Telemetry.init() through TracerSetup
to PostHogSpanExporter, so $ai_generation events show correct values
when CLI is spawned by VS Code.
- KILO_APP_NAME: product name ('kilo-code') — overrides appName
- KILO_EDITOR_NAME: IDE name (vscode.env.appName) — sets editorName only
- Previously both were set to the same 'Kilo VSCode (CLI)' value
- appName: 'kilo-code' (was vscode.env.appName which showed 'Visual Studio Code')
- platform: 'vscode' (was process.platform which showed 'darwin')
- editorName: vscode.env.appName (IDE name, e.g. 'Visual Studio Code')
- vscodeVersion: vscode.version (e.g. '1.109.4')
Previously picked the first binary found in dist (often linux-x64-musl).
Now checks for cli-{platform}-{arch} first (e.g. cli-darwin-arm64).
- Added KILO_VSCODE_VERSION env var passed from extension to CLI
- OTel span exporter now includes editorName and vscodeVersion
- Removed all _debug_* temporary properties from track() and exportSpan()

// Expected: packages/opencode/dist/@kilocode/cli-<platform>/bin/kilo
// But keep it flexible: find any dist/**/bin/kilo
// Prefer the binary matching the current platform (e.g. cli-darwin-arm64)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was copying the linux build for me

@markijbema markijbema marked this pull request as ready for review February 18, 2026 16:45
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 18, 2026

Code Review Summary

Status: No New Issues Found | Recommendation: Address existing comments before merge

Overview

This PR implements a telemetry proxy architecture where the VS Code extension forwards telemetry events to the CLI server via POST /telemetry/capture, which then delivers them to PostHog. The implementation is well-structured with clean separation of concerns:

  • TelemetryProxy (singleton in extension) — enriches events with VS Code context and POSTs to CLI
  • TelemetryRoutes (CLI server) — receives events and forwards to kilo-telemetry
  • Environment variables (KILO_APP_NAME, KILO_TELEMETRY_LEVEL, etc.) — configure CLI-side telemetry from VS Code context
  • Webview bridgecaptureTelemetryEvent() helper posts messages to extension host

The existing inline comments from reviewers cover the key issues. No additional bugs, security vulnerabilities, or runtime errors were found.

Other Observations (not in diff)

Issues found during review that are design considerations rather than bugs:

File Observation
packages/kilo-vscode/src/services/cli-backend/server-manager.ts KILO_TELEMETRY_LEVEL is set once at CLI spawn time. If the user toggles VS Code telemetry settings after the CLI starts, CLI-originated events (OTel spans, session tracking) continue using the stale setting. Extension-originated events are properly gated by TelemetryProxy.isVSCodeTelemetryEnabled(). Consider subscribing to vscode.env.onDidChangeTelemetryEnabled and calling a /telemetry/set-enabled endpoint in a follow-up.
packages/kilo-vscode/src/services/telemetry/telemetry-proxy.ts The TelemetryProxy has no event queuing — events fired before configure() is called (i.e., before CLI connects) are silently dropped. This is likely acceptable for a first implementation but worth noting.
Files Reviewed (25 files)
  • AGENTS.md — 1 existing comment
  • packages/kilo-telemetry/src/__tests__/telemetry.test.ts — updated constructor calls, no issues
  • packages/kilo-telemetry/src/identity.tsKILO_MACHINE_ID env override, clean
  • packages/kilo-telemetry/src/otel-exporter.ts — expanded constructor options, clean
  • packages/kilo-telemetry/src/telemetry.ts — env var overrides for app metadata, clean
  • packages/kilo-telemetry/src/tracer.ts — passes new options through, clean
  • packages/kilo-vscode/docs/non-agent-features/telemetry.md — documentation updates
  • packages/kilo-vscode/script/local-bin.ts — 1 existing comment (platform-specific binary selection)
  • packages/kilo-vscode/src/KiloProvider.ts — 1 existing comment (message.event validation)
  • packages/kilo-vscode/src/extension.ts — telemetry wiring, clean
  • packages/kilo-vscode/src/services/autocomplete/AutocompleteServiceManager.ts — migrated to TelemetryProxy
  • packages/kilo-vscode/src/services/autocomplete/classic-auto-complete/AutocompleteTelemetry.ts — migrated to TelemetryProxy
  • packages/kilo-vscode/src/services/autocomplete/shims/TelemetryStub.ts — deleted (replaced by TelemetryProxy)
  • packages/kilo-vscode/src/services/cli-backend/connection-service.ts — exposes server config, clean
  • packages/kilo-vscode/src/services/cli-backend/server-manager.ts — env vars for CLI telemetry config
  • packages/kilo-vscode/src/services/telemetry/errors.ts — new error types, clean
  • packages/kilo-vscode/src/services/telemetry/index.ts — barrel export, clean
  • packages/kilo-vscode/src/services/telemetry/telemetry-proxy.ts — 5 existing comments
  • packages/kilo-vscode/src/services/telemetry/types.ts — 1 existing comment
  • packages/kilo-vscode/webview-ui/src/components/settings/SettingsRow.tsx — removed stale marker
  • packages/kilo-vscode/webview-ui/src/context/vscode.tsx — exported getVSCodeAPI, clean
  • packages/kilo-vscode/webview-ui/src/types/messages.ts — added TelemetryRequest type, clean
  • packages/kilo-vscode/webview-ui/src/utils/telemetry.ts — webview telemetry helper, clean
  • packages/opencode/src/server/routes/telemetry.ts — 1 existing comment (type safety)
  • packages/opencode/src/server/server.ts — route registration, clean

@markijbema markijbema force-pushed the mark/telemetry-implementation branch from 9bbf55d to fda8a5f Compare February 18, 2026 17:07
}

const payload = JSON.stringify({ event, properties: merged })
const auth = `Basic ${Buffer.from(`kilo:${this.password}`).toString("base64")}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why Basic and not Bearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is to the cli, not the api

Respects --disable-telemetry CLI flag, managed/policy settings, and
other VS Code-level overrides that getConfiguration() misses.
@markijbema markijbema enabled auto-merge February 18, 2026 17:23
@markijbema markijbema merged commit 67107e5 into dev Feb 18, 2026
7 checks passed
@markijbema markijbema deleted the mark/telemetry-implementation branch February 18, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VSCODE][FEATURE]:Add telemetry

2 participants

Comments