Repository navigation
refactor(telemetry): simplify analytics plumbing and close reporting gaps - #78
Open
digitallysavvy wants to merge 9 commits into
Open
digitallysavvy wants to merge 9 commits into
digitallysavvy wants to merge 9 commits into
Conversation
Replace the hidden variadic operations parameter and firstAnalytics helper with an explicit *analyticsOperation argument on initProject, initRecipeProject, resolveInitProjectForScaffold, quickstartCreate, projectCreate and createProject. Uninstrumented callers pass nil; the operation methods stay nil-safe. Record project_action once in resolveInitProjectForScaffold next to setAppID instead of duplicating the block in init.go and recipes.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the runtime opt-out check into telemetry.go as telemetryOptedOut and add telemetryAllowed(preference) as the single gate used by usage analytics (shell startup snapshot and MCP live preference), the MCP telemetry status tool and the diagnostics client constructor. Usage-analytics opt-out semantics are unchanged: DO_NOT_TRACK, AGORA_TELEMETRY_ENABLED=0 and AGORA_SENTRY_ENABLED=0 (OS env only once a config store is attached). The placeholder Sentry client now also honors AGORA_TELEMETRY_ENABLED=0; it is a no-op without a DSN either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build the telemetry status result in one telemetryStatus helper shared by telemetry status/enable/disable and the agora.telemetry.status MCP tool. Shell paths pass the startup preference (already updated by enable and disable); MCP still passes the freshly re-read config preference. Define init stage names and the agent family/surface/detection-source value sets once and use them at emit sites and in validAnalyticsEvent. Wire values are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mcp serve is long-lived, so spawning a detached sender per tool call is unnecessary. MCP operations now send from a background goroutine through the same sendAnalyticsBatch path (validation, 64 KiB limit, ten-second timeout, no redirects, no auth headers). Tool responses never wait for delivery; serveMCP waits at most one second for in-flight batches after the host closes stdin. Shell commands keep the detached subprocess. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
finish() skipped project create on the assumption that createProject had already emitted cli_project_create_completed at the API boundary. A failure before that call (invalid flags, unreadable context, missing MCP name) therefore produced no event. Track whether the boundary event was emitted and, if not, emit the same event with the existing fields from finish(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
submit() accounted for the 64 KiB request limit without the cli_init_started event that flush() prepends (after copying source attribution onto it), so a near-limit batch could pass accounting and then be dropped at flush. Reserve the start event's worst-case size, including attribution, when the operation begins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge analytics_final_test.go and analytics_regression_test.go, which were named after PR history, into analytics_test.go (collection, policy and validation) and analytics_send_test.go (batching and delivery). No test is dropped. Add a test pinning the collector-allowlisted stage and agent value sets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Follow-up to #76. Applies the review recommendations on top of
codex/cli-analytics. This PR changes no event names, property keys or allowed values. It also leaves business JSON output and exit codes as they were.Simplifications
initProject,initRecipeProject,resolveInitProjectForScaffold,quickstartCreate,projectCreateandcreateProjectnow take an explicitop *analyticsOperationinstead of a hidden variadicoperations ...*analyticsOperation.firstAnalyticsis removed. Callers that are not instrumented (quickstart createin the shell and in MCP) passnil. The operation methods are still nil-safe.project_actionis set once. The reused/created block that was copied intoinit.goandrecipes.gois nowop.setProjectAction(...), called inresolveInitProjectForScaffoldnext toop.setAppID. It still runs only when project resolution succeeds.telemetryStatus(action, configPath, preference)builds the result fortelemetry status|enable|disableand for theagora.telemetry.statusMCP tool. Each path produces the same keys and values as before:a.cfg.TelemetryEnabled. For enable and disable this is the value just saved.currentTelemetryPreference(), which re-reads the config file, so a long-running server sees preference changes made after it started.setTelemetrystill resolves the config path before saving, so errors are returned in the same order.analyticsStage*), and the agent family, surface and detection-source lists are defined once. Both the emit sites andvalidAnalyticsEventuse them. A new test,TestAnalyticsAllowlistValuesArePinned, checks the exact values so a change that would break the collector's allowlist fails CI.telemetry.gonow holdstelemetryOptedOut()andtelemetryAllowed(preference). Shell analytics, MCP analytics, the MCP status tool andinitTelemetry(the Sentry placeholder) all use them. Usage-analytics opt-out works exactly as before:DO_NOT_TRACKset to any non-empty valueAGORA_TELEMETRY_ENABLED=0AGORA_SENTRY_ENABLED=0, read froma.env, or only from the OS environment once a config store is attachedmcp serveis long-lived, so MCP operations no longer start a detached subprocess for each tool call. They call the samesendAnalyticsBatchfrom a background goroutine. That function does the decoding and allowlist checks and uses the same HTTP client: 10s timeout, no redirects, 64 KiB limit, no auth headers. The bytes sent over the wire match the shell path because both re-marshal throughanalyticsBatch.serveMCPwaits at most 1s (analyticsMCPDrainTimeout) for batches still in flight.docs/telemetry.mdDelivery section is updated.analytics_final_test.goandanalytics_regression_test.goare merged intoanalytics_test.go(collection, policy and validation) andanalytics_send_test.go(batching and delivery). The suite had 32 test functions before; all of them are kept, and 4 new ones are added. The Windows ACL test, the integration test and the notice test files are unchanged.analytics.go,analytics_sender.go,analytics_process_*.goandtelemetry_notice.go, and thetelemetry.godescription is corrected.Gaps
finish()skippedproject createon the assumption thatcreateProjecthad already sent its event. So a failure before the API call (invalid--featureor--rtm-data-center, an unreadable context file, a missing MCP name) sent nothing. The operation now records whether the API-boundary event was sent. If it was not,finish()sendscli_project_create_completedwith the existing fields (outcome,error_code,duration_ms,exit_code). Test:TestAnalyticsProjectCreateFailureBeforeAPIIsReported(shell and MCP; fails without the fix).beginAnalyticsnow reserves the size ofcli_init_startedup front. The reserve covers the worst case afterflushcopiessource_type,source_idandrecipe_id(each at its maximum length) onto it. Any event thatsubmit()accepts therefore still fits whenflush()adds the start event. The 64 KiB check influshstays as a backstop. Test:TestAnalyticsBatchAccountingIncludesInitStart(fails without the fix).docs/telemetry.mdnow says that a successful project creation is recorded as a success even if a later step such as enabling features fails, and that aproject createfailure before the API call is reported when the command finishes.Wire format and business output
analyticsEventandanalyticsBatchare unchanged, and no event name, property key or allowed value was added, renamed or removed.TestAnalyticsAllowlistValuesArePinnedchecks the value sets."enabled","captureActive"and the other keys) pass without edits.Chose not to do
enabledsemantics, the "anonymous" wording or the consent notice, as scoped.AGORA_TELEMETRY_ENABLED=0and comparesAGORA_SENTRY_ENABLEDwithout trimming whitespace, the same as analytics. No DSN is shipped and the client is a no-op, so nothing observable changes. I kept the analytics rules exact rather than the Sentry ones.docs/telemetry.mdnotes this.Validation
go build ./... && go vet ./... && go test -count=1 ./...GOOS=windows go vet ./...andGOOS=windows go test -c ./internal/cli/(compiles the Windows-only ACL test)go test -race -count=1 ./internal/cli/ -run 'Analytics|Telemetry|MCP'go test -count=3 ./internal/cli/ -run 'Analytics|Telemetry|MCP'(flakiness check)gofmt -l .(clean)./scripts/check-error-codes.shgo run ./cmd/gendocs -check🤖 Generated with Claude Code