Skip to content

Add light optional telemetry#19

Merged
ivpusic merged 2 commits into
mainfrom
light_telemetry
Mar 9, 2026
Merged

Add light optional telemetry#19
ivpusic merged 2 commits into
mainfrom
light_telemetry

Conversation

@ivpusic

@ivpusic ivpusic commented Mar 9, 2026

Copy link
Copy Markdown
Member

CLI basic telemetry data, captured via amplitude sdk. Telemetry can be disabled.

@cursor

cursor Bot commented Mar 9, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Introduces third-party telemetry (Amplitude) and persists a per-user anonymous ID on disk, so failures/privacy expectations and event-sending behavior need careful review despite opt-out controls.

Overview
Adds optional anonymous telemetry for CLI command executions using Amplitude, including duration, success/error status, CLI version, and OS/arch.

Introduces dune config telemetry {enable|disable|status} plus DUNE_NO_TELEMETRY=1/CI auto-disable, persists the setting in ~/.config/dune/config.yaml, and stores/reuses a UUID in ~/.config/dune/anonymous_id.

Updates the CLI entrypoint to initialize a tracking.Tracker, record per-command start time via context, send a success event on completion, and send an error event when command execution fails; release/build pipelines now inject AMPLITUDE_KEY via GoReleaser/GitHub Actions/Makefile ldflags.

Written by Cursor Bugbot for commit 538c30f. Configure here.

@ivpusic ivpusic requested a review from va3093 March 9, 2026 11:21
@coderabbitai

coderabbitai Bot commented Mar 9, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cab38b1b-df14-4c14-91c5-0e19eade9875

📥 Commits

Reviewing files that changed from the base of the PR and between 538c30f and c51f021.

📒 Files selected for processing (3)
  • .goreleaser.yml
  • cmd/auth/auth.go
  • cmd/config/telemetry.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • .goreleaser.yml

📝 Walkthrough

Walkthrough

Adds end-to-end CLI telemetry via Amplitude: build flags and workflow changes to pass AMPLITUDE_KEY, a new tracking package and tests, CLI integration to initialize/record events, telemetry config commands, and config struct extension for telemetry control.

Changes

Cohort / File(s) Summary
Build & Release
/.github/workflows/release.yml, .goreleaser.yml, Makefile, go.mod
Passes AMPLITUDE_KEY into release/build steps and linker (-X main.amplitudeKey); adds github.com/amplitude/analytics-go and uuid dependency.
Config Model & Save Behavior
authconfig/authconfig.go, cmd/auth/auth.go
Adds Telemetry *bool to Config; auth save now loads, updates, and persists existing config instead of overwriting.
CLI Entry / Integration
cli/root.go, cmd/main.go, cmdutil/client.go
Execute signature extended to accept amplitudeKey; captures start time, wires persistent post-run tracking hook, and adds context helpers for tracker and start time.
Config CLI
cmd/config/config.go, cmd/config/telemetry.go
New config command with telemetry subcommands: enable, disable, status; exposes IsTelemetryEnabled() and persists telemetry preference respecting env overrides.
Tracking Implementation & Tests
tracking/tracking.go, tracking/tracking_test.go
New tracking package wrapping Amplitude client: Tracker, Config, New, Track, Shutdown, anon ID persistence; unit tests for disabled behavior, key handling, and anon ID file I/O.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant CLI as CLI Root
    participant Config as Auth Config
    participant Tracker as Tracker
    participant Amplitude as Amplitude API

    User->>CLI: run command
    CLI->>CLI: record start time (PersistentPreRun)
    CLI->>Config: load telemetry setting
    CLI->>Tracker: New(cfg with amplitudeKey, enabled)
    CLI->>CLI: execute command logic
    alt success
        CLI->>CLI: compute duration
        CLI->>Tracker: Track(command_path, status=success, duration)
    else error
        CLI->>Tracker: Track(command_path, status=error, errorMsg, duration)
    end
    Tracker->>Amplitude: send "CLI Command Executed" event
    Amplitude-->>Tracker: ack
    CLI->>Tracker: Shutdown (flush)
    CLI-->>User: return result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • norbertdurcansk
  • va3093
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add light optional telemetry' directly and concisely describes the main change: integrating optional telemetry functionality into the CLI.
Description check ✅ Passed The description 'CLI basic telemetry data, captured via amplitude sdk. Telemetry can be disabled.' is directly related to the changeset, explaining the core functionality being added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands and usage tips.

@ivpusic ivpusic requested a review from norbertdurcansk March 9, 2026 11:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Telemetry subcommands missing skipAuth annotation require authentication
    • Added skipAuth annotation to all telemetry subcommands (telemetry, enable, disable, status) so they can run without API key authentication.
  • ✅ Fixed: dune auth silently resets user telemetry preference
    • Modified auth command to load existing config first and only update APIKey field, preserving the telemetry preference.

Create PR

Or push these changes by commenting:

@cursor push 802e26ade7
Preview (802e26ade7)
diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go
--- a/cmd/auth/auth.go
+++ b/cmd/auth/auth.go
@@ -40,7 +40,15 @@
 		return fmt.Errorf("no API key provided")
 	}
 
-	if err := authconfig.Save(&authconfig.Config{APIKey: key}); err != nil {
+	cfg, err := authconfig.Load()
+	if err != nil {
+		return fmt.Errorf("loading config: %w", err)
+	}
+	if cfg == nil {
+		cfg = &authconfig.Config{}
+	}
+	cfg.APIKey = key
+	if err := authconfig.Save(cfg); err != nil {
 		return fmt.Errorf("saving config: %w", err)
 	}
 

diff --git a/cmd/config/telemetry.go b/cmd/config/telemetry.go
--- a/cmd/config/telemetry.go
+++ b/cmd/config/telemetry.go
@@ -10,8 +10,9 @@
 
 func newTelemetryCmd() *cobra.Command {
 	cmd := &cobra.Command{
-		Use:   "telemetry",
-		Short: "Manage anonymous usage telemetry",
+		Use:         "telemetry",
+		Short:       "Manage anonymous usage telemetry",
+		Annotations: map[string]string{"skipAuth": "true"},
 	}
 	cmd.AddCommand(
 		newTelemetryEnableCmd(),
@@ -23,8 +24,9 @@
 
 func newTelemetryEnableCmd() *cobra.Command {
 	return &cobra.Command{
-		Use:   "enable",
-		Short: "Enable anonymous usage telemetry",
+		Use:         "enable",
+		Short:       "Enable anonymous usage telemetry",
+		Annotations: map[string]string{"skipAuth": "true"},
 		RunE: func(cmd *cobra.Command, _ []string) error {
 			return setTelemetry(cmd, true)
 		},
@@ -33,8 +35,9 @@
 
 func newTelemetryDisableCmd() *cobra.Command {
 	return &cobra.Command{
-		Use:   "disable",
-		Short: "Disable anonymous usage telemetry",
+		Use:         "disable",
+		Short:       "Disable anonymous usage telemetry",
+		Annotations: map[string]string{"skipAuth": "true"},
 		RunE: func(cmd *cobra.Command, _ []string) error {
 			return setTelemetry(cmd, false)
 		},
@@ -43,8 +46,9 @@
 
 func newTelemetryStatusCmd() *cobra.Command {
 	return &cobra.Command{
-		Use:   "status",
-		Short: "Show current telemetry status",
+		Use:         "status",
+		Short:       "Show current telemetry status",
+		Annotations: map[string]string{"skipAuth": "true"},
 		RunE: func(cmd *cobra.Command, _ []string) error {
 			enabled := IsTelemetryEnabled()
 			if enabled {

Comment @cursor review or bugbot run to trigger another review on this PR

Comment thread cmd/config/telemetry.go
Comment thread authconfig/authconfig.go
@ivpusic ivpusic merged commit 446083b into main Mar 9, 2026
3 checks passed
@ivpusic ivpusic deleted the light_telemetry branch March 23, 2026 14:13
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.

2 participants