telemetry: add best-effort usage telemetry recorder - #1378
Open
BolajiOlajide wants to merge 4 commits into
Open
BolajiOlajide wants to merge 4 commits into
BolajiOlajide wants to merge 4 commits into
Conversation
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
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 ./...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes CPL-1005
Adds the
internal/telemetrypackage: aRecorderthat records src-cli usage events to the authenticated Sourcegraph instance via the Telemetry V2recordEventsGraphQL mutation. Recording is strictly best-effort — validation, network, GraphQL, timeout, and old-instance (<5.2) failures are all swallowed (optionally surfaced viaWithDebugfor-v) and never affect the command the user ran. Command identity is carried infeature/actionwith numeric-only, PII-freemetadata(noprivateMetadata), feature/action names are validated against Sourcegraph's server-side naming rules, and eachRecordapplies a short 2s timeout since events are sent synchronously before process exit. This is the foundational package only; wiring it intocmd/src/main.goand the opt-out/suppression logic land in follow-up changes.