Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Earlier entries pre-date this convention and only carry their version's compare

## [Unreleased]

### Added

- Report `savedPreference`, `transportConfigured`, and `captureActive` in telemetry status output. `enabled` continues to reflect runtime opt-outs ([#76](https://github.com/AgoraIO/cli/pull/76)).

### Changed

- Rename the `project show --json` token debug status to `signalingTokenDebugEnabled` and remove the misleading token capability warning from `project doctor`. Update consumers of the old `tokenEnabled` result field.
Expand Down
14 changes: 14 additions & 0 deletions docs/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,20 @@ Safe branch fields by command shape:
- Show/create/update: `projectId`, `feature`, `configId`, `enabled`, `eventIds`, `urlRegion`
- Delete: `projectId`, `feature`, `configId`, `deleted`

### `telemetry status`, `telemetry enable`, `telemetry disable`

The `telemetry` result reports these fields:

- `action` identifies the operation as `status`, `enable`, or `disable`.
- `configPath` is the local configuration file path.
- `doNotTrack` indicates whether `DO_NOT_TRACK` is set to a non-empty value.
- `savedPreference` is the configured telemetry preference.
- `enabled` combines the preference and runtime opt-outs.
- `transportConfigured` indicates whether a valid collector URL is configured.
- `captureActive` requires both `enabled` and `transportConfigured`.

The `agora.telemetry.status` MCP tool returns the same fields.

### `config path`

Example:
Expand Down
18 changes: 12 additions & 6 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ configuration are required before production capture is active.
Events contain a random local installation ID, a per-operation ID, CLI version,
OS/architecture, coarse AI-tool categories, public recipe/template IDs, timings
and structured results. Project/init events can include validated Agora App IDs.
An installation profile can be created in PostHog; website identities are not
linked. OAuth tokens, App Certificates, project names, source code, conversation
An installation profile can be created in PostHog. Agora App IDs can be
associated with Agora projects and companies. OAuth tokens, App Certificates, project names, source code, conversation
content, local paths and raw errors are not included.

Recipe init attempts are labeled as Recipe usage even if the catalog lookup
Expand Down Expand Up @@ -68,10 +68,16 @@ agora telemetry disable --json
agora telemetry enable --json
```

`enabled` reports the saved preference. `transportConfigured` reports whether a
valid collector URL is configured. `captureActive` combines the preference,
runtime opt-out and transport configuration; it does not confirm delivery.
A first-use disclosure is printed to stderr unless quiet mode suppresses it.
`savedPreference` reports the configured preference. `enabled` also accounts
for runtime opt-outs. `transportConfigured` reports whether a valid collector
URL is configured. `captureActive` requires both `enabled` and
`transportConfigured`. It tracks whether capture can start.

Shell commands print a first-use disclosure to stderr unless quiet mode
suppresses it. MCP includes the disclosure in its initialization instructions
when a collector is configured. MCP hosts decide how to present instructions.
The disclosure provides notice. The first instrumented call can collect events
when capture is active.

Any of these signals disables capture:

Expand Down
4 changes: 2 additions & 2 deletions internal/cli/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ func TestAnalyticsProjectCreateFailureBeforeAPIIsReported(t *testing.T) {
if err == nil {
t.Fatal("fixture must fail before the create API call")
}
events := waitAnalyticsEvents(t, read, 1)
waitAnalyticsEvents(t, read, 1)
// Give a duplicate a chance to arrive before asserting exactly one.
time.Sleep(50 * time.Millisecond)
events = read()
events := read()
if len(events) != 1 {
t.Fatalf("want exactly one event, got %+v", events)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/env_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func agoraEnvCatalog() []agoraEnvVar {
{Name: "AGORA_RECIPES_BASE_URL", Category: "endpoints", Description: "Override the versioned Agora recipes API base URL for staging and integration tests.", Default: "https://recipes.agora.io/api/v1"},
{Name: "AGORA_QUICKSTART_<TEMPLATE>_REPO_URL", Category: "endpoints", Description: "Override the clone URL for a specific quickstart template (e.g. AGORA_QUICKSTART_NEXTJS_REPO_URL). Used for workshops, internal forks, and integration tests; everyday users do not set this.", Effect: "https:// | ssh:// | git:// | file:// | git@host:path | absolute local path"},
// Telemetry
{Name: "AGORA_TELEMETRY_URL", Category: "telemetry", Description: "Anonymous collector URL. HTTPS, or loopback HTTP for local tests. No transport without a configured or release-embedded URL."},
{Name: "AGORA_TELEMETRY_URL", Category: "telemetry", Description: "Usage telemetry collector URL. HTTPS, or loopback HTTP for local tests. No transport without a configured or release-embedded URL."},
{Name: "AGORA_TELEMETRY_ENABLED", Category: "telemetry", Description: "When 0, disable all telemetry transport.", Effect: "0 | 1"},
{Name: "DO_NOT_TRACK", Category: "telemetry", Description: "Standard DO_NOT_TRACK convention; hard opt-out of telemetry and file logging.", Effect: "any non-empty value"},
{Name: "AGORA_SENTRY_ENABLED", Category: "telemetry", Description: "When 0, disable telemetry transport even if config has telemetryEnabled=true.", Default: "1", Effect: "0 | 1"},
Expand Down
9 changes: 6 additions & 3 deletions internal/cli/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Notes for agents:
if transport != "stdio" {
return fmt.Errorf("unsupported MCP transport %q; use stdio", transport)
}
a.maybeShowTelemetryNotice(cmd)
return a.serveMCP(cmd.InOrStdin(), cmd.OutOrStdout())
},
}
Expand Down Expand Up @@ -140,13 +139,17 @@ func (a *App) serveMCP(in io.Reader, out io.Writer) error {
func (a *App) handleMCPRequest(req mcpRequest, encoder *json.Encoder) (any, error) {
switch req.Method {
case "initialize":
return map[string]any{
result := map[string]any{
"protocolVersion": mcpProtocolVersion,
"capabilities": map[string]any{
"tools": map[string]any{},
},
"serverInfo": map[string]any{"name": "agora-cli", "version": version},
}, nil
}
if a.analyticsURL() != "" {
result["instructions"] = telemetryDisclosure
}
return result, nil
case "tools/list":
return map[string]any{"tools": mcpTools()}, nil
case "tools/call":
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"time"
)

// telemetryClient is the diagnostics sink interface. Usage analytics uses
// the separate bounded collector in analytics.go; both share the
// telemetryAllowed gate below. The interface is intentionally minimal so the
// production sink can be swapped (e.g. for the Sentry SDK or a file sink in
// tests) without touching call sites in app.go / commands.go.
// telemetryClient is the diagnostics sink interface. Usage analytics uses the
// separate bounded collector in analytics.go; both share the telemetryAllowed
// gate below. This interface is minimal so the sink can be swapped (e.g. for
// the Sentry SDK or a file sink in tests) without touching call sites in
// app.go / commands.go.
//
// Contract for all implementations:
// - All methods MUST be safe to call from any goroutine.
Expand Down
16 changes: 11 additions & 5 deletions internal/cli/telemetry_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package cli

import (
"fmt"
"github.com/spf13/cobra"
"io"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
)

const telemetryDisclosure = `Agora CLI collects usage statistics by default when a collector is configured:
recipes/init/project create results, stages, duration, version, OS/architecture,
public recipe/template IDs, Agora App IDs and coarse AI-tool categories.
Events use a random installation ID with an installation profile in PostHog;
website identities are not linked.
Agora App IDs can be associated with Agora projects and companies.
No code, conversation content, secrets, project names or local paths are collected.
Details: https://agoraio.github.io/cli/telemetry.html
Disable: agora telemetry disable, DO_NOT_TRACK=1 or AGORA_TELEMETRY_ENABLED=0`
Expand All @@ -38,16 +39,21 @@ func (a *App) persistTelemetryChoice(enabled bool) error {

// telemetryStatus is the shared result for `agora telemetry status|enable|disable`
// and the agora.telemetry.status MCP tool. preference is the saved
// telemetryEnabled value the caller considers current.
// telemetryEnabled value the caller considers current: the startup snapshot
// (already updated by enable/disable) for shell commands, or the re-read config
// for MCP. enabled is the effective value after runtime opt-outs;
// savedPreference is the saved value itself.
func (a *App) telemetryStatus(action, configPath string, preference bool) map[string]any {
enabled := a.telemetryAllowed(preference)
transport := a.analyticsURL() != ""
return map[string]any{
"action": action,
"transportConfigured": transport,
"captureActive": a.telemetryAllowed(preference) && transport,
"captureActive": enabled && transport,
"configPath": configPath,
"doNotTrack": strings.TrimSpace(a.env["DO_NOT_TRACK"]) != "",
"enabled": preference,
"enabled": enabled,
"savedPreference": preference,
}
}

Expand Down
56 changes: 53 additions & 3 deletions internal/cli/telemetry_notice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"bytes"
"encoding/json"
"errors"
"os"
"path/filepath"
Expand Down Expand Up @@ -86,12 +87,61 @@ func TestCLITelemetryDefaultJSONAndExcludedCommands(t *testing.T) {
}
waitAnalyticsEvents(t, read, 1)
env["DO_NOT_TRACK"] = "1"
status := runCLI(t, []string{"telemetry", "status", "--json"}, cliRunOptions{env: env})
if !strings.Contains(status.stdout, `"enabled":true`) || !strings.Contains(status.stdout, `"captureActive":false`) || strings.Contains(status.stdout, `"consent"`) {
t.Fatalf("wrong preference status: %s", status.stdout)
for _, action := range []string{"status", "enable"} {
result := runCLI(t, []string{"telemetry", action, "--json"}, cliRunOptions{env: env})
if result.exitCode != 0 || !strings.Contains(result.stdout, `"enabled":false`) ||
!strings.Contains(result.stdout, `"savedPreference":true`) ||
!strings.Contains(result.stdout, `"captureActive":false`) {
t.Fatalf("unexpected telemetry %s result: %+v", action, result)
}
}
disabled := runCLI(t, []string{"telemetry", "disable", "--json"}, cliRunOptions{env: env})
if strings.Contains(disabled.stderr, "Agora CLI collects") {
t.Fatal("disable notice")
}
}

func TestMCPTelemetryDisclosureDoesNotMarkShellNoticeShown(t *testing.T) {
a := analyticsTestApp(t, "https://collector.example/events")
cmd := a.buildMCPCommand()
cmd.SetArgs([]string{"serve"})
cmd.SetIn(strings.NewReader("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\"}\n"))
var stdout, stderr bytes.Buffer
cmd.SetOut(&stdout)
cmd.SetErr(&stderr)
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}

var response struct {
Result struct {
Instructions string `json:"instructions"`
} `json:"result"`
}
if err := json.Unmarshal(stdout.Bytes(), &response); err != nil {
t.Fatal(err)
}
if response.Result.Instructions != telemetryDisclosure || stderr.Len() != 0 {
t.Fatalf("unexpected MCP disclosure: stdout=%q stderr=%q", stdout.String(), stderr.String())
}
if _, err := os.Stat(filepath.Join(a.env["AGORA_HOME"], "telemetry-notice-shown")); !os.IsNotExist(err) {
t.Fatalf("MCP wrote the shell notice marker: %v", err)
}
}

func TestMCPTelemetryStatusReportsEffectiveAndSavedPreference(t *testing.T) {
for _, optOut := range []bool{false, true} {
a := analyticsTestApp(t, "https://collector.example/events")
if optOut {
a.env["DO_NOT_TRACK"] = "1"
}
result, err := a.callMCPTool("agora.telemetry.status", nil, nil)
if err != nil {
t.Fatal(err)
}
status := result.(map[string]any)
if status["savedPreference"] != true || status["enabled"] != !optOut || status["captureActive"] != !optOut || status["transportConfigured"] != true || status["doNotTrack"] != optOut {
t.Fatalf("optOut=%v: unexpected MCP telemetry status %v", optOut, status)
}
}
}
Loading