Skip to content

telemetry: add best-effort usage telemetry recorder - #1378

Open
BolajiOlajide wants to merge 4 commits into
mainfrom
src-cli-usage-telemetry
Open

BolajiOlajide wants to merge 4 commits into
mainfrom
src-cli-usage-telemetry

Conversation

@BolajiOlajide

@BolajiOlajide BolajiOlajide commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Closes CPL-1005

Adds the internal/telemetry package: a Recorder that records src-cli usage events to the authenticated Sourcegraph instance via the Telemetry V2 recordEvents GraphQL mutation. Recording is strictly best-effort — validation, network, GraphQL, timeout, and old-instance (<5.2) failures are all swallowed (optionally surfaced via WithDebug for -v) and never affect the command the user ran. Command identity is carried in feature/action with numeric-only, PII-free metadata (no privateMetadata), feature/action names are validated against Sourcegraph's server-side naming rules, and each Record applies a short 2s timeout since events are sent synchronously before process exit. This is the foundational package only; wiring it into cmd/src/main.go and the opt-out/suppression logic land in follow-up changes.

Add the internal/telemetry package: a Recorder that records src-cli usage
events to the authenticated Sourcegraph instance via the Telemetry V2
recordEvents GraphQL mutation. Recording is strictly best-effort — network,
GraphQL, timeout, and old-instance (<5.2) failures are all swallowed and never
affect the command the user ran. Command identity is encoded in feature/action
with numeric-only metadata (no user content, no privateMetadata), and names are
validated against Sourcegraph's server-side naming rules.
Telemetry must never contaminate command output, but GraphQL request execution can print OAuth reauthorization guidance on HTTP 401 responses. Send telemetry through the authenticated HTTP client directly so failures remain best-effort without interactive output, while preserving authentication and cancellation.

Add regression coverage for OAuth failures, request shape, GraphQL errors, and timeout cancellation.

## Test Plan

- go test ./...
- go test ./internal/telemetry -run 'TestRecord_(AppliesTimeout|TimeoutCancelsHTTPRequest)' -count=20
@BolajiOlajide BolajiOlajide self-assigned this Sep 19, 2026
The telemetry API already validates feature and action names authoritatively, so maintaining a second validator in src-cli adds drift risk without improving correctness. Remove the duplicate validation and allow rejected events to follow the recorder's existing best-effort failure path.

## Test Plan

- go test ./...
The telemetry package has no production callers yet, so exporting event models, source configuration, options, and test-only controls commits src-cli to an API before its integration requirements are known. Keep only the recorder construction and recording operations public, fix the client identity internally, and pass event values directly.

## Test Plan

- go test ./...
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.

1 participant