diff --git a/Taskfile.yml b/Taskfile.yml index f261e03a9..2cbce4aae 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -47,8 +47,9 @@ tasks: build: desc: Build main cmds: - # LDFlags sets the segment endpoint to an empty string so that all it is replaced by the default value - - go build -v -o build/darwin/amd64/circleci -ldflags="-X 'github.com/CircleCI-Public/circleci-cli/telemetry.SegmentEndpoint=' -X 'github.com/CircleCI-Public/circleci-cli/telemetry.SegmentKey=AbgkrgN4cbRhAVEwlzMkHbwvrXnxHh35'" . + # LDFlags sets the segment endpoint to an empty string thus letting the analytics library set the default endpoint on its own + # Not setting the `SegmentEndpoint` variable would let the value in the code ie "http://localhost" + - go build -v -o build/$(go env GOOS)/$(go env GOARCH)/circleci -ldflags="-X 'github.com/CircleCI-Public/circleci-cli/telemetry.SegmentEndpoint=' -X 'github.com/CircleCI-Public/circleci-cli/telemetry.SegmentKey="`echo ${SEGMENT_KEY}`"'" . build-linux: desc: Build main diff --git a/clitest/clitest.go b/clitest/clitest.go index 16fe54085..24b0b25bc 100644 --- a/clitest/clitest.go +++ b/clitest/clitest.go @@ -74,7 +74,7 @@ func WithTempSettings() *TempSettings { tempSettings.Config = OpenTmpFile(settingsPath, "cli.yml") tempSettings.Telemetry = OpenTmpFile(settingsPath, "telemetry.yml") content, err := yaml.Marshal(settings.TelemetrySettings{ - IsActive: false, + IsEnabled: false, HasAnsweredPrompt: true, }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) diff --git a/cmd/create_telemetry/create_telemetry.go b/cmd/create_telemetry/create_telemetry.go index 99b98d4a5..6425df310 100644 --- a/cmd/create_telemetry/create_telemetry.go +++ b/cmd/create_telemetry/create_telemetry.go @@ -87,7 +87,7 @@ func CreateTelemetry(config *settings.Config) telemetry.Client { } loadTelemetrySettings(&telemetrySettings, &user, apiClient, ui) - client := telemetry.CreateClient(user, telemetrySettings.IsActive) + client := telemetry.CreateClient(user, telemetrySettings.IsEnabled) return client } @@ -104,7 +104,7 @@ func loadTelemetrySettings(settings *settings.TelemetrySettings, user *telemetry // If we already have telemetry information or that telemetry is explicitly disabled, skip if settings.HasAnsweredPrompt { // If we have no user id, we try requesting the user id again - if settings.UserID == "" && settings.IsActive { + if settings.UserID == "" && settings.IsEnabled { myID, err := apiClient.GetMyUserId() if err == nil { settings.UserID = myID @@ -120,7 +120,7 @@ func loadTelemetrySettings(settings *settings.TelemetrySettings, user *telemetry // If stdin is not available, send telemetry event, disable telemetry and return if !isStdinATTY { - settings.IsActive = false + settings.IsEnabled = false err := telemetry.SendTelemetryApproval(telemetry.User{ UniqueID: settings.UniqueID, }, telemetry.NoStdin) @@ -136,11 +136,11 @@ func loadTelemetrySettings(settings *settings.TelemetrySettings, user *telemetry fmt.Println("Participation is voluntary, and your choice can be changed at any time through the command `cli telemetry enable` and `cli telemetry disable`.") fmt.Println("For more information, please see our privacy policy at https://circleci.com/legal/privacy/.") fmt.Println("") - settings.IsActive = ui.AskUserToApproveTelemetry("Enable telemetry?") + settings.IsEnabled = ui.AskUserToApproveTelemetry("Enable telemetry?") settings.HasAnsweredPrompt = true // Make sure we have user info and set them - if settings.IsActive { + if settings.IsEnabled { if settings.UniqueID == "" { settings.UniqueID = CreateUUID() } @@ -159,7 +159,7 @@ func loadTelemetrySettings(settings *settings.TelemetrySettings, user *telemetry // Send telemetry approval event approval := telemetry.Enabled - if !settings.IsActive { + if !settings.IsEnabled { approval = telemetry.Disabled } diff --git a/cmd/create_telemetry/create_telemetry_test.go b/cmd/create_telemetry/create_telemetry_test.go index d573d0042..f54bdcfb8 100644 --- a/cmd/create_telemetry/create_telemetry_test.go +++ b/cmd/create_telemetry/create_telemetry_test.go @@ -103,7 +103,7 @@ func TestLoadTelemetrySettings(t *testing.T) { }, want: want{ settings: settings.TelemetrySettings{ - IsActive: true, + IsEnabled: true, HasAnsweredPrompt: true, UserID: userId, UniqueID: uniqueId, @@ -126,7 +126,7 @@ func TestLoadTelemetrySettings(t *testing.T) { }, want: want{ settings: settings.TelemetrySettings{ - IsActive: false, + IsEnabled: false, HasAnsweredPrompt: true, }, telemetryEvents: []telemetry.Event{ @@ -146,7 +146,7 @@ func TestLoadTelemetrySettings(t *testing.T) { }, want: want{ settings: settings.TelemetrySettings{ - IsActive: true, + IsEnabled: true, HasAnsweredPrompt: true, UserID: userId, UniqueID: "other-id", diff --git a/cmd/telemetry.go b/cmd/telemetry.go index 89c52192d..da327cbbf 100644 --- a/cmd/telemetry.go +++ b/cmd/telemetry.go @@ -51,7 +51,7 @@ func setIsTelemetryActive(apiClient create_telemetry.TelemetryAPIClient, isActiv } settings.HasAnsweredPrompt = true - settings.IsActive = isActive + settings.IsEnabled = isActive if settings.UniqueID == "" { settings.UniqueID = create_telemetry.CreateUUID() diff --git a/cmd/telemetry_test.go b/cmd/telemetry_test.go index 764927de2..e8e09145a 100644 --- a/cmd/telemetry_test.go +++ b/cmd/telemetry_test.go @@ -45,7 +45,7 @@ func TestSetIsTelemetryActive(t *testing.T) { apiClient: telemetryTestAPIClient{}, isActive: true, settings: &settings.TelemetrySettings{ - IsActive: false, + IsEnabled: false, HasAnsweredPrompt: true, UniqueID: uniqueId, UserID: userId, @@ -53,7 +53,7 @@ func TestSetIsTelemetryActive(t *testing.T) { }, want: want{ settings: &settings.TelemetrySettings{ - IsActive: true, + IsEnabled: true, HasAnsweredPrompt: true, UniqueID: uniqueId, UserID: userId, @@ -69,7 +69,7 @@ func TestSetIsTelemetryActive(t *testing.T) { }, want: want{ settings: &settings.TelemetrySettings{ - IsActive: true, + IsEnabled: true, HasAnsweredPrompt: true, UniqueID: uniqueId, UserID: userId, @@ -82,7 +82,7 @@ func TestSetIsTelemetryActive(t *testing.T) { apiClient: telemetryTestAPIClient{}, isActive: false, settings: &settings.TelemetrySettings{ - IsActive: true, + IsEnabled: true, HasAnsweredPrompt: true, UniqueID: uniqueId, UserID: userId, @@ -90,7 +90,7 @@ func TestSetIsTelemetryActive(t *testing.T) { }, want: want{ settings: &settings.TelemetrySettings{ - IsActive: false, + IsEnabled: false, HasAnsweredPrompt: true, UniqueID: uniqueId, UserID: userId, @@ -106,7 +106,7 @@ func TestSetIsTelemetryActive(t *testing.T) { }, want: want{ settings: &settings.TelemetrySettings{ - IsActive: false, + IsEnabled: false, HasAnsweredPrompt: true, UniqueID: uniqueId, UserID: userId, diff --git a/cmd/version.go b/cmd/version.go index 8470333db..127d528c8 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -35,6 +35,7 @@ func newVersionCommand(config *settings.Config) *cobra.Command { opts.args = args }, Run: func(_ *cobra.Command, _ []string) { + fmt.Printf("telemetry.SegmentKey = %+v\n", telemetry.SegmentKey) fmt.Printf("%s+%s (%s)\n", version.Version, version.Commit, version.PackageManager()) }, } diff --git a/settings/settings.go b/settings/settings.go index b31797fe2..8e920e5f5 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -63,7 +63,7 @@ type UpdateCheck struct { // TelemetrySettings is used to represent telemetry related settings type TelemetrySettings struct { - IsActive bool `yaml:"is_active"` + IsEnabled bool `yaml:"is_enabled"` HasAnsweredPrompt bool `yaml:"has_answered_prompt"` UniqueID string `yaml:"unique_id"` UserID string `yaml:"user_id"` diff --git a/telemetry/telemetry.go b/telemetry/telemetry.go index 906ef1003..29cf9832f 100644 --- a/telemetry/telemetry.go +++ b/telemetry/telemetry.go @@ -85,8 +85,8 @@ func (cli nullClient) Track(_ Event) error { return nil } // Used when telemetry is enabled type segmentClient struct { - cli analytics.Client - user User + analyticsClient analytics.Client + user User } func newSegmentClient(user User) Client { @@ -145,7 +145,7 @@ func (segment *segmentClient) Track(event Event) error { event.Properties["team_name"] = segment.user.TeamName } - return segment.cli.Enqueue(analytics.Track{ + return segment.analyticsClient.Enqueue(analytics.Track{ UserId: segment.user.UniqueID, Event: event.Object, Properties: event.Properties, @@ -153,7 +153,7 @@ func (segment *segmentClient) Track(event Event) error { } func (segment *segmentClient) Close() error { - return segment.cli.Close() + return segment.analyticsClient.Close() } // File telemetry