From 5b5cf958aaa8e8458a826014d910807752c03c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Tue, 21 Nov 2023 21:11:52 +0000 Subject: [PATCH 1/4] cli: use the gitpod endpoint for analytics --- components/local-app/cmd/root.go | 9 ++++++--- components/local-app/pkg/telemetry/telemetry.go | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/local-app/cmd/root.go b/components/local-app/cmd/root.go index 0505c5fd7ed752..c41d1f5e7b6009 100644 --- a/components/local-app/cmd/root.go +++ b/components/local-app/cmd/root.go @@ -92,13 +92,16 @@ var rootCmd = &cobra.Command{ } cmd.SetContext(config.ToContext(context.Background(), cfg)) + host := "https://gitpod.io" telemetryEnabled := !telemetry.DoNotTrack() telemetryEnabled = telemetryEnabled && cfg.Telemetry.Enabled // For now we only enable telemetry on gitpod.io - if gpctx, err := cfg.GetActiveContext(); err == nil && gpctx != nil { - telemetryEnabled = telemetryEnabled && gpctx.Host.String() == "https://gitpod.io" + gpctx, err := cfg.GetActiveContext() + if err == nil && gpctx != nil { + telemetryEnabled = telemetryEnabled && gpctx.Host.String() == host + host = gpctx.Host.String() } - telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level) + telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level, host) telemetry.RecordCommand(cmd) if !isVersionCommand(cmd) { diff --git a/components/local-app/pkg/telemetry/telemetry.go b/components/local-app/pkg/telemetry/telemetry.go index 81fbb520d82ff6..6c05ac88337650 100644 --- a/components/local-app/pkg/telemetry/telemetry.go +++ b/components/local-app/pkg/telemetry/telemetry.go @@ -25,7 +25,7 @@ import ( ) // Injected at build time -var segmentKey = "TgiJIVvFsBGwmxbnnt5NeeDaian9nr3n" +var segmentKey = "untrusted-dummy-key" var opts struct { Enabled bool @@ -36,7 +36,7 @@ var opts struct { } // Init initializes the telemetry -func Init(enabled bool, identity, version string, logLevel slog.Level) { +func Init(enabled bool, identity, version string, logLevel slog.Level, host string) { opts.Enabled = enabled if !enabled { return @@ -56,7 +56,8 @@ func Init(enabled bool, identity, version string, logLevel slog.Level) { logger = segment.StdLogger(log) } opts.client, _ = segment.NewWithConfig(segmentKey, segment.Config{ - Logger: logger, + Logger: logger, + Endpoint: host + "/analytics", }) } } From 2321a734591eee1122df5bbd7cd2a5342ab6fdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 23 Nov 2023 14:27:19 +0000 Subject: [PATCH 2/4] Remove gitpod.io constraint --- components/local-app/cmd/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/components/local-app/cmd/root.go b/components/local-app/cmd/root.go index c41d1f5e7b6009..b048fb6dd5a529 100644 --- a/components/local-app/cmd/root.go +++ b/components/local-app/cmd/root.go @@ -98,7 +98,6 @@ var rootCmd = &cobra.Command{ // For now we only enable telemetry on gitpod.io gpctx, err := cfg.GetActiveContext() if err == nil && gpctx != nil { - telemetryEnabled = telemetryEnabled && gpctx.Host.String() == host host = gpctx.Host.String() } telemetry.Init(telemetryEnabled, cfg.Telemetry.Identity, constants.Version.String(), level, host) From e8ac00c4c18316150da472ca09269c922950ddda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 23 Nov 2023 17:15:49 +0000 Subject: [PATCH 3/4] Remove unused tomfoolery --- .../local-app/pkg/telemetry/telemetry.go | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/components/local-app/pkg/telemetry/telemetry.go b/components/local-app/pkg/telemetry/telemetry.go index 6c05ac88337650..6c50cfe53bd73a 100644 --- a/components/local-app/pkg/telemetry/telemetry.go +++ b/components/local-app/pkg/telemetry/telemetry.go @@ -24,9 +24,6 @@ import ( "golang.org/x/exp/slices" ) -// Injected at build time -var segmentKey = "untrusted-dummy-key" - var opts struct { Enabled bool Identity string @@ -45,21 +42,19 @@ func Init(enabled bool, identity, version string, logLevel slog.Level, host stri opts.Version = version opts.Identity = identity - if segmentKey != "" { - var logger segment.Logger - if logLevel == slog.LevelDebug { - logger = segment.StdLogger(log.New(os.Stderr, "telemetry ", log.LstdFlags)) - } else { - // we don't want to log anything - log := log.New(os.Stderr, "telemetry ", log.LstdFlags) - log.SetOutput(io.Discard) - logger = segment.StdLogger(log) - } - opts.client, _ = segment.NewWithConfig(segmentKey, segment.Config{ - Logger: logger, - Endpoint: host + "/analytics", - }) + var logger segment.Logger + if logLevel == slog.LevelDebug { + logger = segment.StdLogger(log.New(os.Stderr, "telemetry ", log.LstdFlags)) + } else { + // we don't want to log anything + log := log.New(os.Stderr, "telemetry ", log.LstdFlags) + log.SetOutput(io.Discard) + logger = segment.StdLogger(log) } + opts.client, _ = segment.NewWithConfig("untrusted-dummy-key", segment.Config{ + Logger: logger, + Endpoint: host + "/analytics", + }) } // DoNotTrack returns true if the user opted out of telemetry From ca883fe8a0191eb70a95efd2edd2524daf4be9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 23 Nov 2023 17:23:55 +0000 Subject: [PATCH 4/4] bump version --- components/local-app/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/local-app/version.txt b/components/local-app/version.txt index d917d3e26adc98..b1e80bb2480a6d 100644 --- a/components/local-app/version.txt +++ b/components/local-app/version.txt @@ -1 +1 @@ -0.1.2 +0.1.3